-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomQuiz.py
45 lines (45 loc) · 1.44 KB
/
randomQuiz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/python3- code not tested
import random
state_capitals = {
"Alabama": "Montgomery",
"Alaska": "Juneau",
"Arizona": "Phoenix",
"Arkansas": "Little Rock",
"California": "Sacramento",
"Colorado": "Denver",
"Connecticut": "Hartford",
"Delaware": "Dover",
"Florida": "Tallahassee",
"Georgia": "Atlanta",
"Hawaii": "Honolulu",
"Idaho": "Boise",
"Illinois": "Springfield",
"Indiana": "Indianapolis",
"Iowa": "Des Moines",
"Kansas": "Topeka",
"Kentucky": "Frankfort",
"Louisiana": "Baton Rouge",
"Maine": "Augusta",
"Maryland": "Annapolis"
}
for i in range(5):
file = open('quiz%s.txt'%(i+1),'w')
answer = open('answer%s.txt'%(i+1),'w')
file.write('Name:\nDate\n')
file.write('State capital quiz %s'%(i+1))
states = list(state_capitals.keys())
random.shuffle(states)
for j in range(20):
correct = state_capitals[states[j]]
wrong = list(state_capitals.values())
del wrong[wrong.index(correct)]
wrong_answers = random.sample(wrong,3)
all_options = [correct] + wrong_answers
random.shuffle(all_options)
for k in range(20):
file.write('%s. What is the capital of %s?\n'%(k+1,state_capitals[k]))
for z in range(4):
file.write(' %s. %s\n'%('ABCD'[z]),all_options[z])
answer.write('%s. %s\n'%(k+1,'ABCD'[all_options.index(correct)]))
file.close()
answer.close()