Python Forum
Age Difference to 18 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Age Difference to 18 (/thread-25460.html)



Age Difference to 18 - vejin - Mar-31-2020

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.


RE: Age Difference to 18 - buran - Mar-31-2020

you have missing closing bracket on line#1