类型错误:不支持/的操作数类型:'str' 和 'float' [英] TypeError: unsupported operand type(s) for /: 'str' and 'float'

查看:89
本文介绍了类型错误:不支持/的操作数类型:'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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆