|
2 | 2 |
|
3 | 3 |
|
4 | 4 | # Dictionary that contain the feature as key and his inventer as value
|
5 |
| -question_dict = {'Ballpoint pen': 'Biro Brothers', 'Jet Engine': 'Sir Frank Whittle', |
6 |
| - 'Gramophone': 'Thomas Alva Edison', 'Internal Combustion Engine': 'Otto', |
7 |
| - 'The Spinning Jeny': 'James Hargreaves', 'the small pox vaccine': 'Edward Jenner', |
8 |
| - 'Railway air brakes': 'George Westinghouse', 'Electric streetcar': 'Thomas Davenport', |
9 |
| - 'Electric Generator': 'Michal Faraday', 'Gun Powder': 'Roger Bacon' |
10 |
| - } |
| 5 | +question_dict = { |
| 6 | + 'Ballpoint pen': 'Biro Brothers', 'Jet Engine': 'Sir Frank Whittle', |
| 7 | + 'Gramophone': 'Thomas Alva Edison', 'Internal Combustion Engine': 'Otto', |
| 8 | + 'The Spinning Jeny': 'James Hargreaves', 'the small pox vaccine': 'Edward Jenner', |
| 9 | + 'Railway air brakes': 'George Westinghouse', 'Electric streetcar': 'Thomas Davenport', |
| 10 | + 'Electric Generator': 'Michal Faraday', 'Gun Powder': 'Roger Bacon' |
| 11 | + } |
11 | 12 |
|
12 | 13 | mark = 0
|
13 | 14 | # Turning the dict keys into a random list
|
14 | 15 | question_list = list(question_dict.keys())
|
15 | 16 | random.shuffle(question_list)
|
| 17 | + |
16 | 18 | # loop through the random list of questions
|
17 | 19 | for i, key in enumerate(question_list):
|
18 | 20 | print(40 * '-')
|
19 |
| - print(f'{i + 1}- How invent {key}') |
| 21 | + print(f'Q_{i + 1} - How invent {key}:') |
20 | 22 |
|
21 | 23 | # Give the user 4 choices, be sure that the choices are random and includes the right answer
|
22 | 24 | choices = list(question_dict.values())
|
|
25 | 27 | choices = choices[:3]
|
26 | 28 | choices.append(question_dict[key])
|
27 | 29 | random.shuffle(choices)
|
| 30 | + |
28 | 31 | # Print the choices to the user
|
29 | 32 | for a, b in enumerate(choices):
|
30 |
| - print(f" {a + 1}- {b}") |
| 33 | + print(f" {a + 1} - {b}") |
31 | 34 |
|
32 | 35 | # Taking the user answer
|
33 | 36 | response = int(input('Enter your choice : '))
|
|
38 | 41 | else:
|
39 | 42 | mark -= 0.5
|
40 | 43 |
|
41 |
| - print(question_dict[key]) |
42 |
| -print('-------------------------') |
43 |
| -print(f"You have got {mark}/10") |
| 44 | + # print(question_dict[key]) |
| 45 | + |
| 46 | +print('\n\n-----------------------------') |
| 47 | +print(f" You have got {mark}/10") |
| 48 | +print('-----------------------------') |
0 commit comments