Skip to content

Commit cd43880

Browse files
authored
Can be more convenient
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 : )
1 parent 2d34fc1 commit cd43880

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Guessing_Game.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import random
1+
from random import randint
22

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
44

55
while True: # loop will run until encountered with the break statement(user enters the right answer)
66
userGuess = int(input("Enter your guessed no. b/w 0-100:")) # user input for guessing the number
77
if userGuess < 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
88
print("Guess Higher")
9-
comGuess = random.randint(a, 100)
9+
comGuess = randint(a, 100)
1010
a += 1
1111

1212
elif userGuess > 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
1313
print("Guess Lower")
14-
comGuess = random.randint(0, a)
14+
comGuess = randint(0, a)
1515
a += 1
1616

1717
else: # if guessed correctly the loop will break and the player will win

0 commit comments

Comments
 (0)