本文介绍了类型错误:不支持/的操作数类型:'str' 和 'float'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Python 2,但出现错误:
类型错误:不支持/的操作数类型:'str' 和 'float'当脚本运行到最后一行时.我不明白哪个变量仍然是字符串类型.
from sys import argv脚本,年龄,身高=argv打印你 %r 岁了"%ageweight=input('我需要你的体重来计算BMI,你能告诉我吗:')打印 '你的 BMI 是 %r'%weight/((float(height)/100)**2) 解决方案 from sys import argv脚本,年龄,身高=argv打印你 %r 岁了"%ageweight=input('我需要你的体重来计算BMI,你能告诉我吗:')打印 '你的 BMI 是 %r'%(weight/((float(height)/100)**2))我找到了解决方案,因为%之后的公式必须在()中
I am using Python 2 but I'm getting an error:
TypeError: unsupported operand type(s) for /: 'str' and 'float'when the script runs to the last line. I don't understand which variable is still a string type.
from sys import argv script, age, height=argv print 'you\'re %r old'%age weight=input('and i need your weight to calculate BMI, can you tell me:') print 'your BMI is %r'%weight/((float(height)/100)**2)解决方案 from sys import argv script, age, height=argv print 'you\'re %r old'%age weight=input('and i need your weight to calculate BMI, can you tell me:') print 'your BMI is %r'%(weight/((float(height)/100)**2))
i found the solution, it's because a formula after % must be in ()
更多推荐
类型错误:不支持/的操作数类型:'str' 和 'float'
发布评论