File tree 1 file changed +16
-21
lines changed
1 file changed +16
-21
lines changed Original file line number Diff line number Diff line change 1
- import random , time
2
- print ("Welcome to number guessing game !!!" )
1
+ import random
2
+ import time
3
+ print ('Hello World! Welcome to the game' )
3
4
time .sleep (2 )
4
- #generate a random number
5
- x = random .randint (1 , 10 )
6
- print ("The number is generated!!!" )
7
- time .sleep (1 )
8
- print ("You have 4 chances to guess" )
9
- #initialize the counter
5
+ n = random .randint (1 , 10 )
6
+ print ('Number has been generated!!\n You have 4 chnaces to guess the number' )
7
+
10
8
count = 4
11
- while count != 0 :
12
- a = int ( input ( "Guess the number : " ))
13
- #if number guessed is correct, print correct
14
- if a == x :
15
- print ( "You are right, correct number is " , x )
16
- print ("Congratulations! You won" )
9
+
10
+ while count != 0 :
11
+ a = int ( input ( 'Guess the number: ' ))
12
+
13
+ if a == n :
14
+ print ("Yay! That's right. You won! " )
17
15
break
18
- #if guessed number is greater
19
- elif a > x :
20
- print ("The number is less than " , a )
21
- #if guessed number is smaller
16
+ elif a > n :
17
+ print ('The number is less than ' , a )
22
18
else :
23
- print ("The number is greater than " , a )
24
- #decrease the counter after each guess
25
- count -= 1
19
+ print ('The number is greater than ' , a )
20
+ count = - 1
You can’t perform that action at this time.
0 commit comments