Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
0
Indexable
Never
import random

def attempts(number_of_tries):
  """Prints how many tries
  player has"""
  print(f"You have {number_of_tries} attempts remaining")

print("Welcome to the number guessing game!")

random_number = random.randint(1,100)

print("I'm thinking of a number between 1 and 100")

tries_remaining = 0

while tries_remaining == 0:
  difficulty  = input("Choose a difficulty. Type 'easy' or 'hard': ")
  if difficulty.lower() == "easy":
   tries_remaining = 10
  elif difficulty.lower() == "hard":
    tries_remaining = 5
  else:
    print("Wrong input, try again")

while tries_remaining > 0:
  attempts(tries_remaining)
  guess = input("Make a guess: ")
  if int(guess) < random_number:
    print("Too low.")
    tries_remaining -= 1
    if tries_remaining > 0:
      print("Guess again")
  elif int(guess) > random_number:
    print("Too high.")
    tries_remaining -= 1
    if tries_remaining > 0:
      print("Guess again")
  else:
    print(f"You got it! The answer was {random_number}")
    tries_remaining = 0