-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquize_game.py
More file actions
63 lines (57 loc) · 1.73 KB
/
quize_game.py
File metadata and controls
63 lines (57 loc) · 1.73 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
51
52
53
54
55
56
57
58
59
60
61
62
63
def new_game():
guesses =[]
correct_guesses = 0
question_num = 1
for key in questions:
print('--------------')
print(key)
for i in options[question_num -1]:
print(i)
guesse = input('Enter (A B C)')
guesse = guesse.upper()
guesses.append(guesse)
correct_guesses += check_answer(questions.get(key),guesse)#calling function to check
#if we are guessing correctly or not the key and guesses as a paramater
question_num +=1
display_score(correct_guesses, guesses)
def check_answer(answer,guess):
if answer == guess:
print('Correct')
return 1
else:
print('wrong')
return 0
def display_score(correct_guesses,guesses):
print('----------------')
print('Results')
print('-----------------------------')
print('answers:',end=' ')
for i in questions:
print(questions.get(i),end='')
print()
print('Guesses:',end=' ')
for i in guesses:
print(i,end =' ')
print()
score = int((correct_guesses/len(questions))*100)
print('your score is : ' + str(score) + '%')
def play_again():
response = input('do you want to play again? (y/n)')
response = response.upper()
if response == 'y':
return True
else:
return False
questions = {
"who created python?":'A',
"is the earth rounde?":'B',
"is python a good language?":'C',
"is AI going to kill us?":'A'
}
options = [
["A.guido van rossum",'B.elon f musk','C.zuckerburg'],
["A.yes",'B.no','C.not sure'],
["A.no",'B.yes','C.not sure3'],
["A.no",'B.yes','C.not sure']
]
new_game()