# Python Project: Number Guessing Game

Press Play to try the code:

## CODE

``````import random

print("Welcome to the number guessing game!\n")
print("Give me a range of numbers. I will select a random one in between.")
print("You have ten tries to guess the number I picked.\n")

while True:
try:
starting_range = int(input("Enter a starting number: "))
ending_range = int(input("Enter an ending number: "))

selected_number = random.randint(starting_range, ending_range)
print("\nI picked a number between {} and {}.\n".format(starting_range, ending_range))

for count in range(10):
guess = int(input("Your guess ({} attempts remaining): ".format(10 - count)))

if guess < selected_number:
print("Too low!")
elif guess > selected_number:
print("Too high!")
else:
print("Correct!")
break
else:
print("You are out of attempts. The number I picked was {}.".format(selected_number))
break

except ValueError:
print("Invalid input! Try again.")
``````

[Original code updated with the help of ChatGPT.]

## ORIGINAL CODE

``````import random

print("Welcome to the number guessing game! \n\nGive me a range of numbers. I will select a random one in between. You have ten tries to figure out the number I picked.\n")

try:
starting_range = int(input("Enter a starting number: "))

ending_range = int(input("Now enter an ending number: "))

selected_number = random.randint(starting_range, ending_range)

print("\nI picked a number between {} and {}.\n".format(starting_range, ending_range))

count = 0
while count < 9:
count += 1

if guess < selected_number:
print("Too low!")
guess = int(input("Guess again: "))

elif guess > selected_number:
print("Too high!")
guess = int(input("Guess again: "))

else:
if guess == selected_number:
print("Correct!")
break

except:
print("Not a valid guess! End of game.")
``````