2014-03-31 63 views
0

我無法在我的python測驗代碼中輸入評分。下面是該腳本:輸入評分(python 2.7.5)

#This is the Test script for)TUKT(, Developed by BOT. 
print "" 
print "Welcome to the Ultimate Kirby Test." 
print "" 
begin = (raw_input("Would you like to begin?:")) 
if begin == "yes": 
    print "" 
    print "Alright then! Let's start, shall we?" 
    print "Q1. What color is Kirby?" 
    print "1) Black." 
    print "2) Blue." 
    print "3) Pink." 
    print "4) Technically, his color changes based on the opponent he swallows." 
    choice = input("Answer=") 
    if choice ==1: 
     print "Incorrect." 
     print "" 
    elif choice ==2: 
     print "Incorrect." 
     print "" 
    elif choice ==3: 
     print "Tee hee.... I fooled you!" 
     print "" 
    elif choice ==4: 
     score = score+1 
     print "Well done! You saw through my trick!" 
     print "" 
    elif choice > 3 or choice < 1: 
     print "That is not a valid answer." 
     print "" 
    print "Well done! You have finished my test quiz." 
    print("Score:") 
    print "" 
#End of Script 

錯誤總是說 得分=得分+ 1沒有定義。 我沒有得到任何研究。 謝謝!非常感謝幫助!

+0

在腳本開始處設置'score = 0'。 – Hyperboreus

+0

謝謝你們!這真的回答了我的問題! – boatofturtles

回答

0

varibale score從未被定義過。插入score = 0作爲您的scirpt的第一行。

2

您忘記定義一個名爲score的變量。你不能引用一個不存在的值!

在一開始就聲明它:

score = 0 

在行score = score + 1,巨蟒雲:「,所以我需要創建一個名爲score變量。它包含值score,加上1。'score尚不存在,所以引發錯誤。