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


Messages In This Thread
Age Difference to 18 - by vejin - Mar-31-2020, 11:27 AM
RE: Age Difference to 18 - by buran - Mar-31-2020, 11:34 AM

Forum Jump:

User Panel Messages

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