Python Forum

Full Version: Age Difference to 18
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
you have missing closing bracket on line#1