类型错误:不支持/的操作数类型:'str' 和 'float'

编程入门 行业动态 更新时间:2024-10-14 16:20:59
本文介绍了类型错误:不支持/的操作数类型:'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'

本文发布于:2023-10-28 04:34:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   不支持   错误   操作   float

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!