Skip to main content
 首页 » 编程设计

python之没有跳出 while 循环

2025年05月04日13over140

<分区>

我编写了一些代码,可以掷两个骰子并询问用户多少次。之后它会询问用户是否要再次玩。由于某种原因,它没有在应该跳出的 while 循环中跳出。

代码如下:

import random 
again = True 
rolls = 0 
while again == True: 
    rolls = float(raw_input("How many times would you like the dice to roll?")) 
    while rolls >= 1: 
        dice1 = random.randint(1,6) 
        dice2 = random.randint(1,6) 
        print dice1 , dice2 
        rolls = rolls - 1 
    again = raw_input("Would you like to play again?") 
    if again == "Yes" or "Y" or "yes" or "y": 
        again = True 
    else: 
        again = False 

谁能帮帮我