2017-09-05 1 views
-3

학교 일을 다시 시작한 프로그램을 완료하려하지만 이전에 Python을 사용 해본 적이 없으므로 오류가 발생한 위치를 고민하고 있습니다. 거짓말. 어떤 도움이 목요일까지 선호되는데, 이것이 작업이 마감 될 때입니다!Python NameError : 전역 이름 '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

문제는 들여 쓰기입니다. 그런 변수들을 왜 글로벌 변수로 선언합니까? –

답변

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) 

그냥 다음 프로그램이 들여 쓰기가 꺼져있는 것 같습니다

관련 문제