我正在尝试用 Python 制作课堂掷骰子游戏。下面是我的代码。我无法弄清楚游戏如何完成,即选择“n”时,我从未结束重复最终打印(即“,”我希望您喜欢骰子。祝你有美好的一天!“)
import random
import time
player = random.randint(1,6)
ai = random.randint(1,6)
cont = str(input('Roll the dice? Y/N'))
while cont == "Y":
print ("You are rolling...")
time.sleep(3)
print ("You rolled " + str(player))
print("The computer rolls...." )
time.sleep(3)
print ("The computer rolled " + str(ai))
if player > ai:
print("You win")
if ai > player:
print("You lose")
cont2 = str(input('Would you like to play again? Y/N'))
while cont != "Y" or cont2 != "Y":
break
print ("I hope you enjoyed playing dice. Have a great day!")
慕雪6442864
MMTTMM
相关分类