mardi 21 décembre 2021

Why am I getting this syntax error? (Python)

Python noob here. Took a swing at the 'guess the number game' this afternoon. It all looks fine to me but i keep getting a syntax error on line 26:

else player_number >= secret_number:

I've tried everything but I can't figure it out at all. Thanks for your help.

import random, sys
secret_number = random.randint(1, 99)
countdown_timer = 7

print("This is a number guessing game.")
print("You have to guess a number between 1 and 99!")
print("You have 7 attempts to guess the correct number")
print("Good luck!")
print("\n")
print("Your first guess is: ")

while countdown_timer != 0:
    player_number = int(input())
    countdown_timer = (countdown_timer - 1)
    if player_number == secret_number:
        print("\n")
        print("That's it!! The number was: " + secret_number)
        print("\n")
        print("Congratulations!")
        print("Please try again.")
        quit()
    elif player_number <= secret_number:
        print("Higher!")
        print("You have " + int(countdown_timer) + "guesses left.")
        print("Please enter your next guess: ")
    else player_number >= secret_number:
        print("Lower!")
        print("You have " + int(countdown_timer) + "guesses left.")
        print("Please enter your next guess: ")
        
print("You are out of guesses, sorry.")
print("The correct number was: " + secret_number)
print("Please try again.")



Aucun commentaire:

Enregistrer un commentaire