【发布时间】:2021-06-06 23:12:11
【问题描述】:
这是我编写的代码,它应该告诉我圆的半径,但我一直收到错误。
PI = 3.141593
radius_p = float(input('radius'))
perimeter = 2 * PI * radius_p
print('perimeter: ') + str(perimeter)
# Ask the user for the radius of the room
# Calculate the perimeter
# Print the perimeter
this is what I get after
```
TypeError Traceback (most recent call last)
<ipython-input-80-ba1678e7ffca> in <module>()
2 radius_p = float(input('radius'))
3 perimeter = 2 * PI * radius_p
----> 4 print('perimeter: ') + str(perimeter)
5 # Ask the user for the radius of the room
6 # Calculate the perimeter
TypeError: 'str' object is not callable
【问题讨论】:
-
print('perimeter: ' + str(perimeter)) -
@SeanHsieh 我把它改成了那个,但仍然出现同样的错误
-
我猜问题是您在代码中的某处使用了
str作为变量名。不要使用内置名称作为变量名。 -
那么你接受的答案为什么会出现同样的错误