Search code examples
pythonif-statementstatements

I'm trying to create a program in python that takes the input the user gives and tells them if they're underage or not


I'm new to python and this is what i came up with, it does not work.

age = input("How old are you? ")

if age < 18
    print("You are under age.")
else
    print("You are over age")

Thanks.


Solution

  • The result of the input function must be convert to an int by using the int constructor, like int("123") in order to be compared to the number 18.

    if int(input("How old are you?")) < 18:
      print("You are under age")
    else:
      print("You are over age")