File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
PyGamesScripts/Guess The Number Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ # import random library to use it in this program.
2
+ import random
3
+
4
+ # Variable num generates and stores a random number between 0 to 100.
5
+ num = random .randrange (0 , 100 )
6
+ guessCheck = "wrong"
7
+ print ("--Welcome to Guess The Number Game--" )
8
+
9
+ # Iterate using while loop
10
+ while guessCheck == "wrong" :
11
+ res = int (input ("Please input a number between 0 and 100:" ))
12
+ try :
13
+ val = int (res )
14
+ except ValueError :
15
+ print ("This is not a valid integer. Please try again!" )
16
+ continue
17
+ # Check whether the user input is high or low than the random number generated.
18
+ if val < num :
19
+ print ("This is lower than actual number. Please try again!" )
20
+ elif val > num :
21
+ print ("This is higher than actual number. Please try again!" )
22
+ else :
23
+ # Final result will be printed with this message as the user input matches the random number generated
24
+ print ("Hurray! you won, this is the correct number." )
25
+ guessCheck = "correct"
26
+ print ("Thank you for playing Guess The Number. See you again!" )
You can’t perform that action at this time.
0 commit comments