File tree 1 file changed +22
-9
lines changed
1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change 1
1
from random import randint
2
-
2
+ print ( "Welcome to the Higher-Lower Game!" )
3
3
rnum = randint (0 , 100 )
4
4
noguesses = 0
5
5
while True :
6
- guess = int (input (": " ))
7
- if guess > rnum :
8
- print ("Lower" )
9
- elif guess < rnum :
10
- print ("Higher" )
11
- else :
12
- (print ("You win ({noguesses} guesses used)" ), quit ())
13
- noguesses += 1
6
+
7
+ while True :
8
+ guess = input ("Guess the number: " )
9
+ if guess .isdigit ():
10
+ # Check if the input string consists of digits only
11
+ integer_number = int (guess )
12
+ print ("You entered:" , integer_number )
13
+
14
+ if integer_number > rnum :
15
+ print ("Lower" )
16
+ elif integer_number < rnum :
17
+ print ("Higher" )
18
+ else :
19
+ (print ("You win! the number is " + guess + "!" ), quit ())
20
+ noguesses += 1
21
+ else :
22
+ print ("Invalid input. Please enter an integer number." )
23
+
24
+
25
+
26
+
You can’t perform that action at this time.
0 commit comments