-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessing_Number_From_User.py
More file actions
30 lines (23 loc) · 1.06 KB
/
Copy pathGuessing_Number_From_User.py
File metadata and controls
30 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Program to guess a number by the user from provided random number from 1 to 9 till user says "exit"
#importing random, this alows us to generate the random numbers in between the given range
import random
#Let's ask to pick a random number between 1 and 9
ran = random.randint(1,9)
#Let't initiate some variables for guess and count as 0
guess = 0
count = 0
#We will use while loop here to check that "guess is not the random number" and "guess is not exit"
while guess != ran and guess != exit:
guess = input("Provide a number to see if you are guessed it correctly or not : ")
#if loop to see if the guess = exit or not
if guess == exit:
break
guess = int(guess)
count += 1
if guess < ran:
print("The number {0} you provided is less than randon number".format(guess))
elif guess > ran:
print("The number {0} you provided is higher than random number".format(guess))
else:
print("Superb, you expected it right. The number {0} you provided is exactly same as the random number: {0})".format(guess,ran))
print('And you have taken',count,'tries to guess it')