我是 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
提交
取消