dimanche 12 janvier 2020

Python IF statement is giving "invalid syntax" error. Please let me know what could be the reason

Please let me know the cause of invalid syntax error in my if statement. The error is pointing under the "if" particularly.

random_integer = random.randint(0,10)
i=3

while (i != 0):
  try:
    number = int(input("Enter your number between 0 to 10: "))

    if number > random_integer:
        print("Your number is greater than my number.")
        i -= 1
        print("You have now {} chance(s) left".format(i))

    elif number < random_integer:
        print("Your number is smaller than my number.")
        i -= 1
        print("You have now {} chance(s) left".format(i))

    elif number == random_integer:
        print("Congratulations! you guessed the correct number. You won the Game.")
        print("Thanks for playing.")
        break


  except:
    print("please enter an integer number from 0 to 10. Try again")

Aucun commentaire:

Enregistrer un commentaire