114-2 26/05/28 python 課程
物件導向式user_7903796
python
20 days ago
1.6 kB
5
Indexable
class Circle:
def __init__(self,radius): #初始化
self.radius=radius
def GetArea(self):
return m.pi*self.radius**2
def GetPerimeter(self):
return m.pi*self.radius*2
class student:
def __init__(self,name,height,weight): #初始化
self.name=name
self.height=height
self.weight=weight
def GetName(self):
return self.name
def GetHeight(self):
return self.height
def GetWeight(self):
return self.weight
def GetBMI(self):
BMI = self.weight/(self.height/100)**2
return BMI
class stack:
def __init__(self):
self.S=[]
def isEmpty(self):
return self.S==[]
def push(self,key):
self.S.append(key)
def pop(self):
if self.isEmpty():
print("Underflow")
return None
else:
return self.S.pop()
def display(self):
print("Stack: ",self.S,end= "")
circle1=Circle(5)
circle2=Circle(10)
print("第1個圓:" + "圓面積 =",circle1.GetArea(),"圓周長 =",circle1.GetPerimeter())
print("第2個圓:" + "圓面積 =",circle2.GetArea(),"圓周長 =",circle2.GetPerimeter())
student1 = student("張小明", 170, 70)
student2 = student("王小花", 160, 50)
print("姓名:",student1.GetName(),"身高:",student1.GetHeight(),"體重:",student1.GetWeight(),"BMI:",student1.GetBMI())
print("姓名:",student2.GetName(),"身高:",student2.GetHeight(),"體重:",student2.GetWeight(),"BMI:",student2.GetBMI())
S = stack()
S.push(1),S.push(2),S.push(3),S.pop()
S.display()Editor is loading...
Leave a Comment