学习成长之路

ajiao111 0

# 1、声明一个电脑类:
# 属性:品牌、颜色、内存大小
# 方法:打游戏、写代码、看视频
# class Computer:
#     brand = ‘MacBook Air’
#     color = ‘white’
#     memory = ‘128G’
#
#     def __init__(self, game, code, movie):
#         self.game = game
#         self.code = code
#         self.movie = movie
#
#     def Game(self):
#         print(self.game)
#
#     def Code(self):
#         print(self.code)
#
#     def Movie(self):
#         print(self.movie)
#
#
# if __name__ == ‘__main__’:
#     a = Computer(‘打游戏‘, ‘写代码‘, ‘看视频‘)
#     print(‘电脑品牌为:%s,颜色为:%s,内存为:%s’ % (a.brand, a.color, a.memory))
#     a.Game()
#     a.Code()
#     a.Movie()

# 2、声明一个矩形类:
#    属性:长、宽 方法:计算周长和面积
#    a.创建不同的矩形,并且打印其周长和面积
# class Rectangle:
#     def __init__(self, length, width):
#         self.length = int(length)
#         self.width = int(width)
#
#     def Perimeter(self):
#         per = 2*(self.length + self.width)
#         print(‘周长为:%s’ % per)
#
#     def Area(self):
#         area = self.length * self.width
#         print(‘面积为:%s’ % area)
#
#
# if __name__ == ‘__main__’:
#     a = Rectangle(10, 20)
#     a.Perimeter()
#     a.Area()


发表评论