[英]Python 2.7.5 inputting information into a list using the questions in another list as a prompt
[英]Inputting scoring (python 2.7.5)
我在python測驗代碼中輸入得分時遇到了麻煩。 這是腳本:
#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。 我沒有得到任何研究。 謝謝! 非常感謝幫助!
你忘了定義一個名為score
的變量。 您不能引用不存在的值!
只需在開始時聲明它:
score = 0
在score = score + 1
,Python會: '所以我需要創建一個名為score
的變量。 它包含score
值加1
。 但score
尚不存在,因此會引發錯誤。
從未定義過變量score
。 將score = 0
作為scirpt的第一行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.