Skip to content

Commit 4d7a907

Browse files
committed
Add readme and update code
1 parent 2a188a5 commit 4d7a907

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

01_quiz_game/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Quiz Game with Python
2+
3+
In this python project we build a simple quiz application for terminal.
4+
5+
In this project, you will learn how to:
6+
7+
- Interact with user in the terminal
8+
- How to use python dictionary objects
9+
10+
## Project Description
11+
12+
We have a python dictionary of `10` scientist as keys and there inventions as values:
13+
14+
```python
15+
question_dict = {
16+
'Ballpoint pen': 'Biro Brothers', 'Jet Engine': 'Sir Frank Whittle',
17+
'Gramophone': 'Thomas Alva Edison', 'Internal Combustion Engine': 'Otto',
18+
'The Spinning Jeny': 'James Hargreaves', 'the small pox vaccine': 'Edward Jenner',
19+
'Railway air brakes': 'George Westinghouse', 'Electric streetcar': 'Thomas Davenport',
20+
'Electric Generator': 'Michal Faraday', 'Gun Powder': 'Roger Bacon'
21+
}
22+
```
23+
24+
You need to iterate through the dict keys (inventions) and give the user 4 choices (scientist name), be sure that the choices are random and includes the right answer. The output should look like this:
25+
26+
```console
27+
Q_1 - How invent Electric streetcar
28+
1 - Roger Bacon
29+
2 - Sir Frank Whittle
30+
3 - George Westinghouse
31+
4 - Thomas Davenport
32+
Enter your choice :
33+
```
34+
35+

01_quiz_game/quiz_game.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33

44
# 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+
}
1112

1213
mark = 0
1314
# Turning the dict keys into a random list
1415
question_list = list(question_dict.keys())
1516
random.shuffle(question_list)
17+
1618
# loop through the random list of questions
1719
for i, key in enumerate(question_list):
1820
print(40 * '-')
19-
print(f'{i + 1}- How invent {key}')
21+
print(f'Q_{i + 1} - How invent {key}:')
2022

2123
# Give the user 4 choices, be sure that the choices are random and includes the right answer
2224
choices = list(question_dict.values())
@@ -25,9 +27,10 @@
2527
choices = choices[:3]
2628
choices.append(question_dict[key])
2729
random.shuffle(choices)
30+
2831
# Print the choices to the user
2932
for a, b in enumerate(choices):
30-
print(f" {a + 1}- {b}")
33+
print(f" {a + 1} - {b}")
3134

3235
# Taking the user answer
3336
response = int(input('Enter your choice : '))
@@ -38,6 +41,8 @@
3841
else:
3942
mark -= 0.5
4043

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

Comments
 (0)