0% found this document useful (0 votes)
43 views1 page

Python Number Guessing Game Script

The document contains a Python script for a number guessing game where the player must guess a randomly generated number between 1 and 100. The script tracks the number of attempts and provides feedback on whether the guess is too low, too high, or correct. It also includes error handling for invalid inputs.

Uploaded by

yusufarpan7
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)
43 views1 page

Python Number Guessing Game Script

The document contains a Python script for a number guessing game where the player must guess a randomly generated number between 1 and 100. The script tracks the number of attempts and provides feedback on whether the guess is too low, too high, or correct. It also includes error handling for invalid inputs.

Uploaded by

yusufarpan7
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

Python Basics Script

# Python Basics Script: Number Guessing Game


import random
def number_guessing_game():
number_to_guess = [Link](1, 100)
attempts = 0
print("Guess the number between 1 and 100")
while True:
try:
guess = int(input("Your guess: "))
attempts += 1
if guess < number_to_guess:
print("Too low!")
elif guess > number_to_guess:
print("Too high!")
else:
print(f"Correct! You guessed it in {attempts} tries.")
break
except ValueError:
print("Please enter a valid number.")
if __name__ == "__main__":
number_guessing_game()

You might also like