首页 > 其他分享 >11.1组合

11.1组合

时间:2022-09-07 19:25:30浏览次数:61  
标签:__ name 组合 price 11.1 course print self

# 练习
# 圆环
# 属性: 记录大圆半径,小圆半径
# 实现计算面积: 圆环的面积大圆面积 - 小圆面积
# 实现计算周长 :大圆周长 +小圆周长
# from math import pi
#
#
#
# class Circle:
# def __init__(self,r):
# self.r = r
#
# def area(self):
# return self.r**2*pi
#
#
# def perimeter(self):
# return 2*self.r*pi
#
#
#
#
# class Ring:
# def __init__(self, outer_r, inner_r):
# c1=Circle(outer_r)
# c2 = Circle(inner_r)
# self.outer_r = c1 # 大圆半径
# self.inner_r = c2 # 小圆半径
# # print('self.outer_r',self.outer_r)
# # print('inner_r',self.inner_r)
# #
# def area(self):
# '''面积'''
# return self.outer_r.area() -self.inner_r.area()
#
# def perimeter(self):
# '''周长'''
# return self.outer_r.perimeter() + self.inner_r.perimeter()
#
#
# r1=Ring(10,5)
# print(r1.area())
# print(r1.perimeter())


# class Student:
# def __init__(self, name, sex, age, course):
# self.name = name
# self.sex = sex
# self.age = age
# self.course = course
#
#
#
# class Course:
# def __init__(self,cname,period,price):
# self.cname =cname
# self.period =period
# self.price = price
#
# php=Course('php','3个月',18000)
# python =Course('python','5个月',25000)
# golang = Course('go','2个月',17000)
#
# banzhang = Student('班长','男',24,'python')
# # print(banzhang.course)
#
# banzhang.course = python
# print(banzhang.course.cname)
# print(banzhang.course.price)
# print(banzhang.course.period)
#



class Student:
def __init__(self, name, sex, age, course_name,course_period,course_price):
self.name = name
self.sex = sex
self.age = age
self.course_name = course_name
self.course_period = course_period
self.course_price = course_price



# banzhang = Student('班长','男',24,'python','5个月',26000)
# laoding = Student('老丁','男',22,'java','5个月',30000)
# laozhao = Student('老赵','男',21,'python','5个月',26000)

# banzhang.course_price = 29000
# laozhao.course_price = 29000
# print(banzhang.course_price)
# print(laozhao.course_price)

# 正常这样写

# class Student:
# def __init__(self, name, sex, age, course):
# self.name = name
# self.sex = sex
# self.age = age
# self.course = course
#
#
#
# class Course:
# def __init__(self,cname,period,price):
# self.cname =cname
# self.period =period
# self.price = price
#
# php=Course('php','3个月',18000)
# python =Course('python','5个月',25000)
# golang = Course('go','2个月',17000)
#
# banzhang = Student('班长','男',24,'python')
# laoding = Student('老丁','男',22,'java')
# laozhao = Student('老赵','男',21,'python')
# banzhang.course = python
# laozhao.course =python
# print(banzhang.course.price)
# print(laozhao.course.price)
# python.price = 29000
#
# print(banzhang.course.price)
# print(laozhao.course.price)



class A:
def __init__(self,name):
self.name = name


a=A('张三 啊')
# a 是对象, 是A的对象
# a.name # 对象a的属性
print(a.name) # a.name是个字符串
a.name.split(' ')
'张三 啊'.split(' ')

标签:__,name,组合,price,11.1,course,print,self
From: https://www.cnblogs.com/zhh0125/p/16666919.html

相关文章