将原始输入变量除以数字时出现 Python TypeError [英] Python TypeError when dividing a raw input variable by a number
本文介绍了将原始输入变量除以数字时出现 Python TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将输入的磅重量转换为公斤,但出现以下错误...
I want to convert an entered lb weight to kg and I get the following error...
类型错误:不支持/的操作数类型:'unicode' 和 'float'
TypeError: unsupported operand type(s) for /: 'unicode' and 'float'
我的代码:
lbweight = raw_input("Current Weight (lb): ")
kgweight = lbweight/2.20462
有人请帮忙!
推荐答案
raw_input
返回一个字符串,您应该使用 float()
将输入转换为浮点数:>
raw_input
returns a string, you should convert the input to float using float()
:
float(raw_input("Current Weight (lb): "))
这篇关于将原始输入变量除以数字时出现 Python TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文