我正在学习 Python 并且正在研究随机掷骰子。当我运行它时,它会重复在询问您是否要再次播放后首先显示的相同数字。我需要帮助找到我在这里出错的地方。
我尝试移动代码并放置不同种类的代码。我只是被难住了。
import sys
import random
import time
greeting = "Welcome to my Dice Game!"
roll = "Lets roll this die!"
die = random.randint(0, 6)
print(greeting)
time.sleep(2)
answer = input("Want to play?")
while answer == "yes" or answer == "y":
print(roll)
time.sleep(2)
print(die)
answer = input("Want to play again?")
print("Thanks for playing!")
这就是我得到的:
Welcome to my Dice Game!
Want to play?yes
Lets roll this die!
5
Want to play again?yes
Lets roll this die!
5
Want to play again?y
Lets roll this die!
5
qq_笑_17
GCT1015
相关分类