-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.py
More file actions
50 lines (36 loc) · 1.12 KB
/
quiz.py
File metadata and controls
50 lines (36 loc) · 1.12 KB
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
46
47
48
49
50
def main():
print("Main Choice: Choose 1 of 3 choices")
print("1. Ask Questions")
print("2. Add a Question")
print("3. Exit Game")
choice = input ("Please make a choice: ")
score=[]
score= 0
if choice == "1":
f = open('questions.txt', 'r')
lines = f.read().split('\n')
f.close()
for line in lines:
question, answer= line.split(',')
guess= input(question+":").lower()
if guess == answer:
print("You're right")
score+=1
else:
print("WRONG")
print(score)
elif choice == "2":
f = open('questions.txt', 'a')
new_question = (input("Ask a question: "))
questions = f.write('\n'+ new_question +",")
new_answer = (input("Answer please: "))
questions = f.write(new_answer)
print(questions)
f.close()
elif choice == "3":
print("Bye Bye")
return None
else:
print("please enter valid option")
main()
main()