【发布时间】:2019-11-28 18:42:06
【问题描述】:
import sys, random
def rand():
number = random.randint(0, 100)
def start():
print("Entrez un nombre et essayez de faire correspondre le nombre aléatoire")
guess= int(input())
def check():
print (guess, number)
if guess == number:
print ("Les nombres sont le même!")
print ("Recomence?")
reawn=str(input())
if reawn == "oui":
rand()
start()
check()
elif guess < number:
print ("Ton nombre est plus grands que le nombre aléatoire!")
print ("Essaye encore?")
reawn=str(input())
if reawn == "oui":
start()
check()
elif guess > number:
print ("Ton nombre est plus petit que le nombre aléatoire!")
print ("Essaye encore?")
reawn=str(input())
if reawn == "oui":
start()
check()
rand()
start()
check()
Traceback(最近一次调用最后一次): 文件“F:\Dominic\Python\rando.py”,第 36 行,在 查看() 文件“F:\Dominic\Python\rando.py”,第 10 行,检查中 打印(猜测,数字) NameError: name 'guess' is not defined
【问题讨论】:
-
这能回答你的问题吗? Python Global Variables - Not Defined?
-
变量
guess在两个函数中都是局部的。这就是为什么在check()中无法识别它,您正在尝试使用未定义的变量。 Python 告诉你:... NameError: name 'guess' is not defined
标签: python random python-3.6