首先,您需要调用函数,如前所述。我还认为从userGuess()内部调用maxNum()是有意义的,因此只需在底部调用userGuess()。在
其次,max_int只在maxNum()函数中定义,因此userGuess()无法访问该函数,您将得到一个错误。在
所以,像这样:from time import sleep
from random import randint
print("Starting up...")
def maxNum(max_int):
print("The maximum number to guess is %d" % max_int)
def userGuess():
max_int = 6
maxNum(max_int)
guess1 = int(input("Guess what number you think the dice will land on? >"))
if guess1 > max_int:
print("You chose a number higher than the maximum number allowed!")
else:
print("Rolling...")
sleep(1)
print("The number is...")
sleep(2)
print(randint(1,6))
userGuess()