mercredi 28 octobre 2020

Where do I need to place the if statement?

I need to print this output:

Guess the price and win the prize!
Enter your guess:46000
Too high!
Enter your guess:45000
Too high!
Enter your guess:44000
Too high!
Enter your guess:43000
Too high!
Enter your guess:42000
Too low!
Enter your guess:42500
Too many guesses!

This is my code:

guess_count = 0
car_price = 42500 

print("Guess the price and win the prize!")
while guess_count <= 5:
   guess_count = guess_count + 1
   guess = int(input("Enter your guess:"))

  if guess == car_price:
    print("You won the car!")
  elif guess < car_price:
    print("Too low!")
  elif guess > car_price:
    print("Too high!")
  if guess_count > 5:
    print("Too many guesses!")

If I input 5 guesses, the code above gives me an output like this:

  Too low!
  Too many guesses!

When a user inputs more than 5 guesses, I just want to print:

  Too many guesses!

What do I need to fix?

Aucun commentaire:

Enregistrer un commentaire