Can't get raw_input to return a number

醉酒当歌 提交于 2019-12-02 11:25:37

raw_input always returns a string object. You need to explicitly convert this into a number object if you plan to use it as such (perform mathematical operations on it):

weight = int(raw_input())

#or

weight = float(raw_input())

Use int if the number will always be an integer. Otherwise, use float if the input can have a decimal part such as 10.1.

raw_input() returns a string. You will need to cast your weight to float:

weight = float(weight)

Or in one line:

weight = float(raw_input())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!