【发布时间】:2020-11-09 11:09:10
【问题描述】:
- 编写一个 Python 程序,该程序接受用户提供的圆的半径并计算面积。转到编辑器 样本输出: r = 1.1 面积 = 3.8013271108436504
我的代码:
def rad_to_area(rad):
from math import pi
area = pi * (rad**2)
return area
radius = input('Enter radius of circle: ')
print('The area of the circle is', rad_to_area(radius))
错误:
Traceback (most recent call last):
File "/tmp/sessions/167965d8c6c342dd/main.py", line 6, in <module>
print('The area of the circle is', rad_to_area(radius))
File "/tmp/sessions/167965d8c6c342dd/main.py", line 3, in rad_to_area
area = pi * (rad**2)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
谁能解释一下我做错了什么?
谢谢
【问题讨论】: