### Python Exercise 3 - Guess The Number

In this tutorial, I have given Exercise 3 (Guess The Number). You can check this question and can try to solve it. It uses simple loops and conditional statements. The problem statement is:

You have to build a "Number Guessing Game," in which a winning number is set to some integer value. The Program should take input from the user, and if the entered number is less than the winning number, a message should display that the number is smaller and vice versa.

#### Instructions:

1. You are free to use anything we've studied till now.
2. The number of guesses should be limited, i.e (5 or 9).
3. Print the number of guesses left.
4. Print the number of guesses he took to win the game.
5. “Game Over” message should display if the number of guesses becomes equal to 0.
You are advised to participate in solving this problem. This task helps you to become a good problem solver and helps you accepting the challenge and acquiring new skills.

## You must be logged in to post a comment!

### Comments(10) Ankit0651 1 year, 8 months ago
`Hii` harry 1 year, 2 months ago
`Hey ankit` SachinJ 1 year, 7 months ago
```n= 18

while(True):
a= input("enter the number")
if int(a)<18:
print("input is smaller")
continue
elif int(a)>18 :
print("input is bigger")
else:
print("correct", int(a) )
break``` mmishra 1 year, 6 months ago
```num = 18
actaulattempt = 5
attempt = actaulattempt
while attempt > 0:
question = "Enter number to guess " + str(attempt) + " attempt remain:"
print(question, end=" ")
inputnum = int(input())
if inputnum > num :
print("your guess number is greater then actual  number")
elif inputnum < num:
print("your guess number is lesser then actual  number")
else:
print("You won, you guess correct number in ",((actaulattempt-attempt)+1)," attempt")
break
attempt = attempt - 1;

print("Game over, you not guess correct number")``` Robin 1 year, 3 months ago
```n = 16
num_of_Guess = 5

for i in range(num_of_Guess):
num = int(input("Enter your number: "))
if num == n:
print("You guessed right its ", n)
break
elif num + 2 == n or num - 2 == n or num + 1 == n or num - 1 == n:
print("You are really close")
else:
num_of_Guess = num_of_Guess - 1
print("Incorrect! try again")
continue``` Manav_Seng 1 year, 1 month ago
```Name: Manav Sengupta

Solution:

# Code with Harry Excercise 3 -- Guess the Number
Number = 56
No_of_Guesses=9
while(True):
if(No_of_Guesses<1):
temp2=int(input(("Game Over! Enter 1 to Continue else Enter anything")))
if(temp2!=1):
break
No_of_Guesses=9
guess=int(input("Enter your guess\n"))
if(guess != Number):
No_of_Guesses=No_of_Guesses-1
temp= guess>Number
if(temp):
verdict="Greater"
else:
verdict="Lesser"
print("Your Guess is "+verdict+" than the Number\n")
continue
else:
print("Congratulations! You got it Right!")
break
print(147*"*"+"\n*"+145*" "+"*\n*"+9*" "+"Thanks for checking out my code, and a ton of thanks to CodewithHarry Channel for all the Quality Content for Free"+22*" "+"*\n*"+145*" "+"*\n"+147*"*") # Gratitude
``` GaziAbbas 11 months ago
```# Gues the Number

guesno = 14
chance = 9
isSucess = False

while (chance > 0):
print("You Have ",chance," Chance to Gues the No")
userno = int(input("Gues Number: "))
chance = chance - 1
if userno == guesno:
isSucess = True
break
else:
if (userno > guesno):
gap = userno - guesno
if gap <= 5:
print("Thoda Number Kam Karo Bhai")
else:
print("Number Kam Karo Bhai")
else:
gap = guesno - userno
if gap <= 5:
print("Thoda Number Badhav Bhai")
else:
print("Number Badhav Bhai")

if isSucess:
print("You Win This Game")
else:
print("Game Over")``` Susheel 11 months ago
```#Susheel Sharma
while(1):
i=int(input("enter ur number"))
if i>n and guess!=1:
print("ur number is greater")
guess=guess-1
print("ur r left with chance= ",guess)
continue
elif i<n and guess!=1:
print("ur number is lesser ")
guess=guess-1
print("ur r left with chance= ", guess)
continue
elif i==n:
print("ur guess in correct")
break
else:
print("ur chances are over")
break``` Vivek-Mishra 9 months, 3 weeks ago
`Thanks, Harry Bhai for Awesome Tutorials |:::::::::::::::::| Full Notes and Source Code :::::::::::::} https://github.com/Optimized-World/Complete-Python-Tutorial-and-Notes` wbaig390 9 months ago
```I'm facing some problems..can you guide me on how it is done?

print("enter the number from 1 till 10 in just 3 tries")
print("enter 1st number")
n1 = input()
print("enter 2nd number")
n2 = input()
print("enter 3rd number")
n3 = input()

if n1 < 5:
print("little more")
elif n1 == 5:
print("Great Job you guessed the number having all the hints")
else :
print ("a bit lesser")

if n2 < 5 :
print("Little more")
elif n2 == 5:
print("Great Job you guessed the number having 2 hints left")
else:
print("A bit Lesser")

if n3 < 5:
print("little more")
elif n3 == 5:
print("Great Job you guessed the number having only one hint left")
else:
print("A bit more")

```

#### Resources

No downloadable resources for this video. If you think you need anything, please post it in the QnA!

#### Course Announcements

Any Course related announcements will be posted here