CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day08/circle.py
Views: 729
1
"""
2
练习
3
修一个游泳池 半径(以米为单位)在程序运行时输入 游泳池外修一条3米宽的过道
4
过道的外侧修一圈围墙 已知过道的造价为25元每平米 围墙的造价为32.5元每米
5
输出围墙和过道的总造价分别是多少钱(精确到小数点后2位)
6
7
Version: 0.1
8
Author: 骆昊
9
Date: 2018-03-08
10
"""
11
12
import math
13
14
15
class Circle(object):
16
17
def __init__(self, radius):
18
self._radius = radius
19
20
@property
21
def radius(self):
22
return self._radius
23
24
@radius.setter
25
def radius(self, radius):
26
self._radius = radius if radius > 0 else 0
27
28
@property
29
def perimeter(self):
30
return 2 * math.pi * self._radius
31
32
@property
33
def area(self):
34
return math.pi * self._radius * self._radius
35
36
37
if __name__ == '__main__':
38
radius = float(input('请输入游泳池的半径: '))
39
small = Circle(radius)
40
big = Circle(radius + 3)
41
print('围墙的造价为: ¥%.1f元' % (big.perimeter * 115))
42
print('过道的造价为: ¥%.1f元' % ((big.area - small.area) * 65))
43
44