我有這樣的代碼:如何在Python中創建分數計數器?
def quiz():
print("Here is a quiz to test your knowledge!")
print()
print("Question 1")
print("How tall is the Eiffel Tower?")
print("a. 350m")
print("b. 342m")
print("c. 324m")
print("d. 1000ft")
answer = input("Make your choice : ")
if answer == "c" :
print ("Correct!")
if answer == "a" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "d" :
print ("Wrong!")
print()
print("Question 2")
print("How loud is a sonic boom?")
print("a. 160dB")
print("b. 175dB")
print("c. 157dB")
print("d. 213dB")
answer = input("Make your choice : ")
if answer == "d" :
print ("Correct!")
if answer == "a" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "c" :
print ("Wrong!")
print()
print("Question 3")
print("How hot is Pluto?")
print("a. 223⁰C to -233⁰C")
print("b. -323⁰C to -347⁰C")
print("c. -375⁰F to -395⁰F")
print("d. -213⁰C to -237⁰C")
answer = input("Make your choice : ")
if answer == "c" :
print ("Correct!")
score + 1
if answer == "a" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "d" :
print ("Wrong!")
print()
print("Question 4")
print("How many calories in a normal Twix bar?")
print("a. 284")
print("b. 297")
print("c. 314")
print("d. 329")
answer = input("Make your choice : ")
if answer == "a" :
print ("Correct!")
score + 1
if answer == "c" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "d" :
print ("Wrong!")
print()
print("Question 5")
print("How deep is Mariana Trench?")
print("a. 12.9km")
print("b. 11.7km")
print("c. 12.4km")
print("d. 11.0km")
answer = input("Make your choice : ")
if answer == "d" :
print ("Correct!")
score + 1
if answer == "a" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "c" :
print ("Wrong!")
print()
print("Question 6")
print("How many states are there in the USA?")
print("a. 50")
print("b. 59")
print("c. 65")
print("d. 48")
answer = input("Make your choice : ")
if answer == "a" :
print ("Correct!")
score + 1
if answer == "c" :
print ("Wrong!")
if answer == "b" :
print ("Wrong!")
if answer == "d" :
print ("Wrong!")
print()
print("Question 7")
print("How many balls on a snooker table?")
print("a. 25")
print("b. 22")
print("c. 21")
print("d. 19")
answer = input("Make your choice : ")
if answer == "b" :
print ("Correct!")
score + 1
if answer == "a" :
print ("Wrong!")
if answer == "c" :
print ("Wrong!")
if answer == "d" :
print ("Wrong!")
print(score)
我想插入一個比分反超這將每個用戶得到一個正確的和不執行任何操作,當他們得到一個錯誤的時間增加一個點。我希望它非常簡單和易於編寫(我是Python新手)。
我該怎麼做?
考慮使用「其他」,而不是多個'IFS ... wrong' – 2014-12-06 23:07:03