我正在制作一个程序来构建测验。 我需要从第一个循环中获取“真实”,以便将其用于第二个循环。
就像现在一样,Python说"true" is not defined
。
def verif(): #this is the function to check if answer was right
y=(chosen_answer.get())
true=0
if chosen_answer==1:
true=true+1
else:
true=true #at the end true represents the number of correct answers
return true
def final_count():
if true==2: #here it shows that "true" was not identified
print("All of the answers were answered correctly!")
elif true==1:
print("50% were answered correctly")
else:
print("none of the answers were right..")
答案 0 :(得分:1)
Pass是一个参数:
def final_count(true):
if true==2:
print("All of the answers were answered correctly!")
elif true==1:
print("50% were answered correctly")
else:
print("none of the answers were right..")
因为您return
函数中的verif
,您只需运行
true = verif()
final_count(true)
我建议将变量名称从true
更改为count
或基本上任何其他内容。此外,在处理局部变量时,您不必保持相同的名称