我在这里有一个简单测验的程序,我一直试图找到一种方法来得分,但无论你在测验中得到什么,它都说我得分为1.
我只能找到获得多项选择测验的方法,但这个测验使用字典和循环。
Capitalquiz = {
'Alabama' : 'Montgomery',
'Alaska' : 'Juneau',
'Arizona' : 'Phoenix',
'Arkansas' : 'Little Rock',
'California' : 'Sacramento',
'Colorado' : 'Denver',
'Connecticut' : 'Hartford',
'Delaware' : 'Dover',
'Florida' : 'Tallahasse',
'Georgia' : 'Atlanta',
'Hawaii' : 'Honolulu',
'Idaho' : 'Boise',
'Illinois' : 'Springfield',
'Indiana' : 'Indianapolis',
'Iowa' : 'Des Moines',
'Kansas' : 'Topeka',
'Kentucky' : 'Frankfort',
'Louisiana' : 'Baton Rouge',
'Maine' : 'Augusta',
'Maryland' : 'Annapolis',
'Massachusettes' : 'Boston',
'Michigan' : 'Lansing',
'Minnesota' : 'St.Paul',
'Mississippi' : 'Jackson',
'Missouri' : 'Jefferson City',
'Montana' : 'Helena',
'Nebraska' : 'Lincoln',
'Nevada' : 'Carson City',
'New Hampshire' : 'Concord',
'New Jersey' : 'Trenton',
'New York' : 'Albany',
'New Mexico' : 'Santa Fe',
'North Carolina' : 'Raleigh',
'North Dakota' : 'Bismarck',
'Ohio' : 'Columbus',
'Oklahoma' : 'Oklahoma City',
'Oregon' : 'Salem',
'Pennsylvania' : 'Harrisburg',
'Rhode Island' : 'Providence',
'South Carolina' : 'Columbia',
'South Dakota' : 'Pierre',
'Tennessee' : 'Nashville',
'Texas' : 'Austin',
'Utah' : 'Salt Lake City' ,
'Vermont' : 'Montpelier',
'Virginia' : 'Richmond',
'Washington' : 'Olympia',
'West Virginia' : 'Charleston',
'Wisconsin' : 'Madison',
'Wyoming' : 'Cheyenne',
}
import sys
print ("Welcome to the State Capitals quiz to complete this quiz type the capitals of the states provided.")
begin = input("Would you like to begin?: ")
if begin == "yes":
print(" ")
else:
print ("Ok please try again later!")
sys.exit()
import random
states = list(Capitalquiz.keys())
for i in [1, 2, 3, 4, 5]:
state = random.choice(states)
capital = Capitalquiz[state]
capital_guess = input("What is the capital of " + state + "? ")
if capital_guess == capital:
print ("That is correct good job!")
score = + 1
else:
print("That is not correct. The capital of " + state + " is " + capital + ".")
print("You got ", score, "out of 5 points")
print("Quiz Complete.")
答案 0 :(得分:2)
我认为这是你在得分计数器上的语法。 尝试:
score = score + 1
而不是
score = +1
因为这会将得分重置为1。
此外,您需要在运行测验之前将分数初始设置为零(例如,在导入随机语句后:分数= 0)