从零开始学Python

Python习题册004:计算圆面积

2019-01-13  本文已影响0人  iLester

任务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
上一篇 下一篇

猜你喜欢

热点阅读