File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ You try to guess a number between 0 and 10
9
9
* functions
10
10
* random numbers
11
11
* imports
12
- * ` f ` strings
12
+ * ` f ` strings
13
+ * try/except
Original file line number Diff line number Diff line change @@ -8,16 +8,20 @@ def main():
8
8
number = randint (0 , 10 )
9
9
not_finished = True
10
10
while not_finished :
11
- guess = int (input ('Guess the number between 0 and 10: ' ))
12
- returned = game (guess , number )
13
- if returned > 0 :
14
- print ('Guessed higher' )
15
- guessed_times += 1
16
- elif returned < 0 :
17
- print ('Guessed lower' )
18
- guessed_times += 1
19
- else :
20
- not_finished = False
11
+ try :
12
+ guess = int (input ('Guess the number between 0 and 10: ' ))
13
+ returned = game (guess , number )
14
+ if returned > 0 :
15
+ print ('Guessed higher' )
16
+ guessed_times += 1
17
+ elif returned < 0 :
18
+ print ('Guessed lower' )
19
+ guessed_times += 1
20
+ else :
21
+ not_finished = False
22
+ except ValueError :
23
+ print (f"Your guess should be a number!" )
24
+
21
25
print (f'End of the game, the number was { number } and you guessed\
22
26
{ guessed_times } times!' )
23
27
You can’t perform that action at this time.
0 commit comments