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 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 : )
print(f"Okay {name} Let's Begin The Guessing Game!")
3
10
a=comGuess=randint(0, 100) # a and comGuess is initialised with a random number between 0 and 100
4
-
11
+
count=0
5
12
whileTrue: # loop will run until encountered with the break statement(user enters the right answer)
6
13
userGuess=int(input("Enter your guessed no. b/w 0-100:")) # user input for guessing the number
7
14
8
15
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
9
16
print("Guess Higher")
10
17
comGuess=randint(a, 100)
11
18
a+=1
19
+
count=1
12
20
13
21
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
14
22
print("Guess Lower")
15
23
comGuess=randint(0, a)
16
24
a+=1
25
+
count=1
26
+
27
+
elifuserGuess==comGuessandcount==0: # the player needs a special reward for perfect guess in the first try ;-)
28
+
print("Bravo! Legendary Guess!")
17
29
18
30
else: #Well, A Congratulations Message For Guessing Correctly!
19
31
print("Congratulations, You Guessed It Correctly!")
0 commit comments