python博客作业4
面向对象
class Person:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def kan(self):
print(f"{self.name},{self.age}岁,{self.sex},上山去砍柴")
def car(self):
print(f"{self.name},{self.age}岁,{self.sex},开车去东北")
def game(self):
print(f"{self.name},{self.age}岁,{self.sex},最爱打游戏")
son = Person('小明', 10, '男')
father = Person('老李', 90, '男')
son.kan()
son.car()
son.game()
print()
father.kan()
father.car()
father.game()
面向过程
activity = ["上山去砍柴","开车去东北","最爱打游戏"]
for i in range(3):
print("小明,10岁,男,"+activity[i])
print()
for i in range(3):
print("老李,90岁,男,"+activity[i])