我正在尝试在 python 中创建一个程序,该程序接受用户提供的输入并告诉他们他们是否未成年

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

我是 python 的新手,这是我想出的方法,但行不通。

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

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

谢谢。

必须使用 int 构造函数将 input 函数的结果转换为 int,如 int("123") 以便与数字 18.

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

input 的类型是什么?嗯,让我们打开 REPL 看看。

$ ipython
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.6.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: age = input('how old are you?')
how old are you?10

In [2]: type(age)
Out[2]: str

In [5]: age == '10'
Out[5]: True

In [6]: age == 10
Out[6]: False

看看 Python 如何处理 strint 不同的类型?

您还忘记了 if statememt

后的冒号 :