我是 python 的新手,这是我想出的,它不起作用。age = input("How old are you? ")if age < 18 print("You are under age.")else print("You are over age")谢谢。
2 回答
RISEBY
TA贡献1856条经验 获得超5个赞
必须使用构造函数将函数的结果input转换为 an ,以便与 number 进行比较。intintint("123")18
if int(input("How old are you?")) < 18:
print("You are under age")
else:
print("You are over age")
慕桂英546537
TA贡献1848条经验 获得超10个赞
的类型是什么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 如何处理str不同于int?
您还忘记了:冒号if statememt
添加回答
举报
0/150
提交
取消