【发布时间】:2016-07-11 05:55:12
【问题描述】:
我想知道如何在函数中使用变量,然后在函数之外使用。 这是我的代码的一部分,它应该在答案正确时将分数加 1,然后打印出总分(有多个函数,所以我需要分数在函数之外):
score=0
def Geography(score):
#Question 1
qa1= input("What is the capital of England? ")
if qa1.lower() == ("london"):
print ("Correct you gain 1 point")
score=score+1
else:
print ("Incorrect")
Geography(score)
print ("This quiz has ended. Your score is " , score, ".")
如您所见,我尝试使用参数,但无论该人是否正确回答,代码最后仍将分数返回为 0。
【问题讨论】:
标签: function variables if-statement arguments python-3.4