Skip to content

Commit d93acfa

Browse files
authored
Update Guessing_Game.py
Try to make the code simpler and instead of importing the whole module I imported the "randint" method and the same with the time module. As result, the program will be compiled in the possible least execution time. Thank you : )
1 parent 73bf0f2 commit d93acfa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Guessing_Game.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
from random import randint
2+
from time import sleep
23

4+
print("Hello Welcome To The Guess Game!")
5+
sleep(1)
6+
print("I\'m Geek! What's Your Name?")
7+
name = input()
8+
sleep(1)
9+
print(f"Okay {name} Let's Begin The Guessing Game!")
310
a = comGuess = randint(0, 100) # a and comGuess is initialised with a random number between 0 and 100
4-
11+
count = 0
512
while True: # loop will run until encountered with the break statement(user enters the right answer)
613
userGuess = int(input("Enter your guessed no. b/w 0-100:")) # user input for guessing the number
714

815
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
916
print("Guess Higher")
1017
comGuess = randint(a, 100)
1118
a += 1
19+
count = 1
1220

1321
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
1422
print("Guess Lower")
1523
comGuess = randint(0, a)
1624
a += 1
25+
count = 1
26+
27+
elif userGuess == comGuess and count == 0: # the player needs a special reward for perfect guess in the first try ;-)
28+
print("Bravo! Legendary Guess!")
1729

1830
else: #Well, A Congratulations Message For Guessing Correctly!
1931
print("Congratulations, You Guessed It Correctly!")

0 commit comments

Comments
 (0)