Python Number Guesser Code
#!/usr/bin/python3
# Import from random library
import random
# Import from sys
from sys import exit
# Generate a random number between 1 and 1000
number = random.randint(1, 1000)
# To go 10 turns
tries = 10
# Print statement to welcome you
print(" WELCOME TO PYTHON NUMBER GUESSER ")
print(" ")
print(" YOU HAVE TO GUESS FROM 1 TO 1000 ")
print(" YOU HAVE 10 GUESSES TO FIND THE RANDOM COMPUTER NUMBER")
print(" ")
print(" HAVE A GREAT TIME ENJOY ")
print(" ")
# How many tries you get to start with
while tries > 0:
# This tells you to guess a number and you input your number
guess = int(input("Guess the number (1-1000): "))
# If guess is correct print the statement below
if guess == number:
# Print statement if you get the number right
reDo = input("Go Again? Press for yes, or 'n' for no: ")
if reDo == "n" or reDo == "N":
print("GOOOODBYE")
# End the game
break
elif guess < number:
# To say if it was higher
print("The number is higher.")
else:
# To say if the number is lower
print("The number is lower.")
# Every time you guess, the tries lower by one try
tries -= 1
# If tries are at zero, give a print statement saying you lost all your tries and the number
if tries == 0:
print("Sorry, you've used all your tries. The number was", number)