title | course |
---|---|
練習六 Q6.py |
S2 - Intermediate Python Programming |
已知求體積為
- 建立一個
Sphere
類別,內含一個__init__(r)
函數,可將rad
屬性值設為r
。 - 試在
Sphere
類別中,定義volume()
函數,來回傳球體積。 - 試在
Sphere
類別中,定義surface_area()
函數,來回傳球表面積。 - 試建立一個
rad=2
的Sphere
類別的物件s0
,並求出物件的體積和表面積。 - 在
Sphere
類別中,定義__repr__()
,當Sphere
被查詢時,回傳Sphere object, rad=r
字串。r
為rad
的值。 - 在
Sphere
類別中,定義__repr__()
,當Sphere
被以print()
印出時,回傳Sphere object, rad= r, volume=v, surface_area=s
字串。r
為rad
的值。