Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Age Difference to 18
#1
Hello,

I want to write a small program that outputs the age difference in years to 18:

x = int(input("Please enter your age: ")

if x > 18:
    y = x - 18
    print("You are" +int(y) +"year(s) older than an 18 year old.")

elif x < 18:
    y = 18 - x
    print("You will turn 18 in" +int(y) +"years")

elif x == 18:
    print("You are the perfect age")

else:
    print("incorrect value entered.")
I get the following error message:

Error:
File "/home/pc/PycharmProjects/begin/howfar18.py", line 3 if x > 18: ^ SyntaxError: invalid syntax Process finished with exit code 1
Thank you for your help.
Reply
#2
you have missing closing bracket on line#1
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020