小编Nin*_*nja的帖子

如何在Python中打破while循环?

我必须为我的comp课程制作这个游戏,我无法弄清楚如何突破这个循环.看,我必须通过滚动更大的数字来对抗"计算机",看看谁有更高的分数.但我无法弄清楚如何从轮到我"打破",并转向计算机转向.我需要"Q"(退出)来表示计算机开始转动,但我不知道该怎么做.

ans=(R)
while True:
    print('Your score is so far '+str(myScore)+'.')
    print("Would you like to roll or quit?")
    ans=input("Roll...")
    if ans=='R':
        R=random.randint(1, 8)
        print("You rolled a "+str(R)+".")
        myScore=R+myScore
    if ans=='Q':
        print("Now I'll see if I can break your score...")
        break
Run Code Online (Sandbox Code Playgroud)

python break while-loop

23
推荐指数
4
解决办法
13万
查看次数

标签 统计

break ×1

python ×1

while-loop ×1