美文网首页从零开始学Python
Python习题册004:计算圆面积

Python习题册004:计算圆面积

作者: iLester | 来源:发表于2019-01-13 22:10 被阅读0次

任务004描述

编写一个Python程序,接收由用户输入的半径值(弧度),程序输出面积值。

思路及示例

首先基础几何知识告诉我们圆的面积与半径的关系是:S = po * r^2


示意

所以,这里实际上就是要使用一下input()语句来接收用户输入,并转换为数值型,再用表达式来计算圆的面积。

示例代码:

import math
r = float(input("please input the radius of the circle:"))
area = math.pi * r**2
print("The area of the circle with radius {} is {}".format(r, area))

输出:

please input the radius of the circle:15
The area of the circle with radius 15.0 is 706.8583470577034

相关文章

网友评论

    本文标题:Python习题册004:计算圆面积

    本文链接:https://www.haomeiwen.com/subject/wyfrdqtx.html