0% found this document useful (0 votes)
28 views2 pages

Mini Python Project Number Guessing Game

Uploaded by

d21461006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Mini Python Project Number Guessing Game

Uploaded by

d21461006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mini Python Project: Number Guessing Game

This is a simple Python project where users guess a randomly generated number.

The game provides feedback if the guess is too high or too low, and continues until the correct

number is guessed.

Code Example:

-------------

import random

def number_guessing_game():

print("Welcome to the Number Guessing Game!")

number_to_guess = random.randint(1, 100)

attempts = 0

while True:

try:

user_guess = int(input("Guess a number between 1 and 100: "))

attempts += 1

if user_guess < number_to_guess:

print("Too low! Try again.")

elif user_guess > number_to_guess:

print("Too high! Try again.")

else:

print(f"Congratulations! You've guessed the number in {attempts} attempts.")

break
except ValueError:

print("Please enter a valid integer.")

if __name__ == "__main__":

number_guessing_game()

You might also like