You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try to make the code more simpler and instead of importing the whole module I imported the "randint" method.
In result the program will be compiled in the possible least execution time.
Thank you : )
Copy file name to clipboardExpand all lines: Guessing_Game.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
-
importrandom
1
+
fromrandomimportrandint
2
2
3
-
a=comGuess=random.randint(0, 100) # a and comGuess is initialised with a random number between 0 and 100
3
+
a=comGuess=randint(0, 100) # a and comGuess is initialised with a random number between 0 and 100
4
4
5
5
whileTrue: # loop will run until encountered with the break statement(user enters the right answer)
6
6
userGuess=int(input("Enter your guessed no. b/w 0-100:")) # user input for guessing the number
7
7
ifuserGuess<comGuess: # if number guessed by user is lesser than the random number than the user is told to guess higher and the random number comGuess is changed to a new random number between a and 100
8
8
print("Guess Higher")
9
-
comGuess=random.randint(a, 100)
9
+
comGuess=randint(a, 100)
10
10
a+=1
11
11
12
12
elifuserGuess>comGuess: # if number guessed by user is greater than the random number than the user is told to guess lower and the random number comGuess is changed to a new random number between 0 and a
13
13
print("Guess Lower")
14
-
comGuess=random.randint(0, a)
14
+
comGuess=randint(0, a)
15
15
a+=1
16
16
17
17
else: # if guessed correctly the loop will break and the player will win
0 commit comments