2017-09-05 186 views
-3

我正在尝试完成一个已被设置为回校工作的程序,但我之前从未使用过Python,所以我正在努力查看错误的位置所在。任何帮助将不胜感激,最好周四,因为这是工作到期!Python名称错误:未定义全局名称'score'

#revision platform 
def Spelling(): 
    global test 
    global score 
    score = 0 
print("Welcome to the Spelling test.") 
Q1=raw_input("Which spelling is correct:\nChangeable\nChangeble\n") 
if Q1=="Changeable": 
    print("Correct") 
    score += 1 
else: 
    print("Incorrect") 
Q2=raw_input("Which spelling is correct:\nThreshhold\nThreshold\n") 
if Q2=="Threshold": 
    print("Correct") 
    score += 1 
else: 
    print("Incorrect") 
Q3=raw_input("Which spelling is correct:\nScent\nSent\nCent\n") 
if Q3=="Scent" or Q3=="Sent" or Q3=="Cent": 
    print("Trick Question they were all right!") 
    score += 1 
    print("Your score is:" ,score) 
else: 
    print("Incorrect") 
    print("Your score is:",score) 

谢谢你的帮忙!

+2

它看起来像你的缩进关闭。 –

+0

你会得到什么错误?你能更具体地说明问题是什么吗?如果您可以添加追踪以及 –

+0

这将是有帮助的问题是缩进。但为什么你将这些变量声明为全局? python中的 –

回答

0
#revision platform 
def Spelling(): 
    score = 0 
    print("Welcome to the Spelling test.") 
    Q1=raw_input("Which spelling is correct:\nChangeable\nChangeble\n") 
    if Q1=="Changeable": 
     print("Correct") 
     score += 1 
    else: 
     print("Incorrect") 
    Q2=raw_input("Which spelling is correct:\nThreshhold\nThreshold\n") 
    if Q2=="Threshold": 
     print("Correct") 
     score += 1 
    else: 
     print("Incorrect") 
    Q3=raw_input("Which spelling is correct:\nScent\nSent\nCent\n") 
    if Q3=="Scent" or Q3=="Sent" or Q3=="Cent": 
     print("Trick Question they were all right!") 
     score += 1 
     print("Your score is:" ,score) 
    else: 
     print("Incorrect") 
     print("Your score is:",score) 

只需拨打拼写()函数,那么你的程序将工作

相关问题