-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmcq_input.py
More file actions
24 lines (20 loc) · 718 Bytes
/
mcq_input.py
File metadata and controls
24 lines (20 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
print('When prompted for an answer, type only the alphabet\n')
ip_file = 'question_and_answers.txt'
total_questions = 0
correct_answers = 0
with open(ip_file) as ipf:
for line in ipf:
if line.startswith('--> '):
answer = line[4]
line = line[4:]
total_questions += 1
print(line, end='')
if line == '\n':
usr_ip = input('Enter you answer: ')
if usr_ip == answer:
correct_answers += 1
print('Correct answer!')
else:
print(f'Oops! The right choice is: {answer}')
print('-' * 50 + '\n')
print(f'You answered {correct_answers}/{total_questions} correctly.\n')