我一直在尝试这段代码,除非我猜错了数字,否则一切正常,然后它会循环回来询问骰子上有多少面,而不是让你猜另一个数字。我究竟做错了什么?
import random
def guessDice():
try:
numSides = int(input("\nHow many sides are on your dice? "))
print("\nYour dice is being rolled...")
while True:
numGuess = int(input("\nPick a number from 1 to " + str(numSides) + " "))
randNum = random.randint(1, numSides)
if numGuess == randNum:
print("\nCongrats! You got it!")
break
else:
print("\nSorry, you guessed the wrong number! Try again.")
except ValueError:
print("\nYou typed in the wrong value. This time, type an integer!")
guessDice()