伟大的髂骨 2023-04-15 11:29 采纳率: 100%
浏览 22
已结题

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'
为什么啊?哪位老哥指导指导,我就是想让输入的数据变成整型而已啊。

  • 写回答

3条回答 默认 最新

  • 社区专家-Monster-XH 2023-04-15 12:00
    关注

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

    father_height = int(float(input("请输入父亲的身高:")))
    mother_height = int(float(input("请输入母亲的身高:")))
    son_height = int((father_height + mother_height) * 0.54)
    print(f"预测儿子的身高为:{son_height}")
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月23日
  • 已采纳回答 4月15日
  • 创建了问题 4月15日