-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflashcards.py
More file actions
43 lines (32 loc) · 943 Bytes
/
flashcards.py
File metadata and controls
43 lines (32 loc) · 943 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# sys is a module. It lets us access command line arguments, which are
# stored in sys.argv.
import sys
import random
if len(sys.argv) < 2:
print("Please supply a flash card file.")
exit(1)
flashcard_filename = sys.argv[1]
f = open(flashcard_filename, "r")
question_dict = {}
for line in f:
entry = line.strip().split(",")
question = entry[0]
answer = entry[1]
question_dict[question] = answer
f.close()
print("Welcome to the flashcard quizzer.")
print("At any time, type 'quit' to quit.")
print("")
questions = list(question_dict.keys())
while True:
question = random.choice(questions)
answer = question_dict[question]
print("Question: " + question)
user_input = input("Your guess: ")
if user_input == "quit":
print("Thanks for playing! Goodbye.")
break
elif user_input == answer:
print("Correct!")
else:
print("Sorry, the answer was: " + answer)