输入为整数

时间:2018-06-07 18:42:08

标签: python python-3.x

我正在玩Python3。我希望weight成为一个int,但我不知道我做错了什么。

age = input("How old are you? ")
height = input("How tall are you? ")
#Since I want to play around, I just want to Turn KG to LBS
#Below is where I'm stuck
weight = int(round(input("How much do you weight? ")*2.2046))

print(f"so you are {age} old, {height} tall and {weight}LBS heavy")

提前致谢。

1 个答案:

答案 0 :(得分:3)

您必须首先将输入(string)转换为int / float,然后才能对其进行数字操作(*)。< / p>

weight = round(int(input("How much do you weight? "))*2.2046)

注意首先评估int(input('...weight?')),然后评估*2.2046部分,最后评估round()