forked from hastagAB/Awesome-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquizzer.py
More file actions
24 lines (21 loc) · 679 Bytes
/
quizzer.py
File metadata and controls
24 lines (21 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import random
import argparse
parser = argparse.ArgumentParser(description="Get the quiz questions file")
parser.add_argument('file', help="a quiz file containing questions and answers")
args = parser.parse_args()
file = args.file
state_capitals = {}
with open(file) as f:
for line in f:
(key, val) = line.strip().split(',')
state_capitals[key] = val
while(True):
choice = random.choice(list(state_capitals.keys()))
answer = input(('{}? '.format(choice)))
if answer == state_capitals[choice]:
print("Correct! Nice job.")
elif answer.lower() == "exit":
print("Goodbye")
break
else:
print("Incorrect. The correct answer is {}".format(state_capitals[choice]))