This project is a simple number guessing game implemented in Python. The program generates a random number between 1 and 100, and the player has to guess the number. The program provides feedback on whether the guessed number is too low or too high until the correct number is guessed.
To run this project on your machine, ensure you have Python installed. Follow these steps:
import random
n = random.randrange(1,100)
guess = int(input("Enter any number: "))
while n!= guess:
if guess < n:
print("Too low")
guess = int(input("Enter number again: "))
elif guess > n:
print("Too high!")
guess = int(input("Enter number again: "))
else:
break
print("you guessed it right!!")
import random
n = random.randrange(1,100)
guess = int(input("Enter any number: "))
while n!= guess:
if guess < n:
print("Too low")
guess = int(input("Enter number again: "))
elif guess > n:
print("Too high!")
guess = int(input("Enter number again: "))
else:
break
print("you guessed it right!!")
1. Import the random module.
2. Generate a random number between 1 and 100.
3. Prompt the user to enter a guess.
4. While the guessed number is not equal to the random number:
a. If the guessed number is less than the random number, print "Too low" and prompt for another guess.
b. If the guessed number is greater than the random number, print "Too high" and prompt for another guess.
5. Once the correct number is guessed, print "You guessed it right!!"
1. Import the random module.
2. Generate a random number between 1 and 100.
3. Prompt the user to enter a guess.
4. While the guessed number is not equal to the random number:
a. If the guessed number is less than the random number, print "Too low" and prompt for another guess.
b. If the guessed number is greater than the random number, print "Too high" and prompt for another guess.
5. Once the correct number is guessed, print "You guessed it right!!"
Q: How can I modify the range of numbers?
A: Change the arguments in random.randrange() to set a different range.
Q: How can I add a feature to count the number of guesses?
A: Initialize a counter variable and increment it each time the user makes a guess.
Q: What if the user wants to quit the game?
A: Add a condition to check if the user enters a specific value (e.g., 0) to exit the loop and end the game. Use a prompt to inform the user of this option.
Office:- 660, Sector 14A, Vasundhara, Ghaziabad, Uttar Pradesh - 201012, India