必须使用构造函数将函数的结果input转换为 an ,以便与 number 进行比较。intintint("123")18if int(input("How old are you?")) < 18: print("You are under age")else: print("You are over age")
的类型是什么input?嗯,让我们打开 REPL 看看。$ ipythonPython 3.6.9 (default, Nov 7 2019, 10:44:02)Type 'copyright', 'credits' or 'license' for more informationIPython 7.6.1 -- An enhanced Interactive Python. Type '?' for help.In [1]: age = input('how old are you?')how old are you?10In [2]: type(age)Out[2]: strIn [5]: age == '10'Out[5]: TrueIn [6]: age == 10Out[6]: False看看 Python 如何处理str不同于int?您还忘记了:冒号if statememt