【发布时间】:2014-05-27 16:38:12
【问题描述】:
我一直在研究 Python 上的毕达哥拉斯定理计算器 到目前为止,这是我的代码:
a = int(raw_input("what is length a?"))
b = int(raw_input("what is length b?"))
a2 = a*a
b2 = b*b
c2 = a2+b2
c = c2**0.5
print "the length of c is " + c
它在最后一行不起作用。它抛出以下错误:
cannot concatenate 'str' and 'float' objects
有谁知道它有什么问题吗?
【问题讨论】:
-
正是错误所说的 - 它不能将字符串(“c 的长度为”)和浮点数(
c)放在一起。您需要通过强制转换来告诉它将该数字视为字符串。 -
下次试试google。当我用谷歌搜索“无法连接 'str' 和 'float' 对象”时,我得到了大约 50 个结果
标签: python