Python3.10 问题

Python3.10 问题

father_height = float(input("请输入父亲的身高:"))
mother_height = float(input("请输入母亲的身高:"))
son_height = float((father_height + mother_height) * 0.54)
print(f"预测儿子的身高为:{son_height}")
在Pycharm中这样的代码就是正确的,能够运行。
father_height = int(input("请输入父亲的身高:"))
mother_height = int(input("请输入母亲的身高:"))
son_height = int((father_height + mother_height) * 0.54)
print(f"预测儿子的身高为:{son_height}")
这段代码在Pycharm中就是错误的,有如下显示:
请输入父亲的身高:182.3
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\pythonProject3\main.py", line 39, in
father_height = int(input("请输入父亲的身高:"))
ValueError: invalid literal for int() with base 10: '182.3'
为什么啊?哪位老哥指导指导,我就是想让输入的数据变成整型而已啊。

我的pycharm可以运行,你不能运行的话,就再强转一次:

father_height = int(float(input("请输入父亲的身高:")))
mother_height = int(float(input("请输入母亲的身高:")))
son_height = int((father_height + mother_height) * 0.54)
print(f"预测儿子的身高为:{son_height}")


img

我截图就是这样的