我正在尝试创建一个骰子游戏,但是在游戏完成之后,我希望它再次以“您是否要再次掷骰子”这个问题开始,而不是转到第一个语句。据我所知,这还不确定如何纠正代码。任何帮助深表感谢!!
import random
dice_number = random.randint(1, 6)
play = True
while play:
roll_dice = input("Would you like to roll the dice?")
if roll_dice.lower() == 'yes':
print(dice_number)
else:
print("Let us play later then.")
break
again = str(input("Do you want to roll the dice again?"))
if again == 'yes':
print(dice_number)
if again == 'no':
play = False
print("It has been fun playing with you.")
continue
尝试这个:
import random
dice_number = random.randint(1, 6)
play = True
first = True
while play:
again = input("Would you like to roll the dice?") if first else str(input("Do you want to roll the dice again?"))
first = False
if again.lower() == 'yes':
print(dice_number)
else:
print("Let us play later then.")
break
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句