首页 > 其他分享 >Chapter 7

Chapter 7

时间:2022-12-13 12:34:06浏览次数:31  
标签:Chapter __ color self init print def

Geese

class Geese:
    '''大雁类'''
    def __init__(self,beak,wing,claw):
        print('我是大雁类!我有以下特征:')
        print(beak)
        print(wing)
        print(claw)
    def fly(self,state):
        print(state)

beak_1='喙的基部较高,长度和头部的长度几乎相等'
wing_1='翅膀长而尖'
claw_1='爪子是蹼状的'
wildGoose=Geese(beak_1,wing_1,claw_1)
wildGoose.fly('我飞行的时候,一会儿排成个人字,一会儿排成个一字')

Geese_a

class Geese:
    '''雁类'''
    neck='脖子较长'
    wing='振翅频率高'
    leg='腿位于身体的中心支点'
    number=0
    def __init__(self):
        Geese.number+=1
        print('\n我是第'+str(Geese.number)+'只大雁,我属于雁类!我有以下特征:')
        print(Geese.neck)
        print(Geese.wing)
        print(Geese.leg)
list1=[]
for i in range(4):
    list1.append(Geese())
print('一共有'+str(Geese.number)+'只大雁')

Film

zd=ZiDong()
print('\n请选择正在上映的电影:1 《环太平洋》2 《头号玩家》3 《红海行动》')
zd.select_film('《头号玩家》')
print('\n请选择电影播放场次:1 9:30 2 10:40 3 12:00')
zd.select_time('10:40')
print('\n请选择座位剩余座位:10-01,10-02,10-03,10-04')
zd.select_seat('10-03')
print('\n正在出票。。。')
zd.film_1='《头号玩家》'
zd.time_1='10:40'
zd.seat_1='10-03'
print('\n电影:'+zd.film_1)  
print('\n时间:'+zd.time_1)
print('\n座位:'+zd.seat_1)
        
print('\n出票完成,请别忘记取票')

Fruit

class Fruit:
    color='绿色'
    def harvest(self,color):
        print('水果是:'+color+'的!')
        print('水果已经收获...')
        print('水果原来是:'+Fruit.color+'的!')
class Apple(Fruit):
    color='红色'
    def __init__(self):
        print('我是苹果')
class Orange(Fruit):
    color='绿色'
    def __init__(self):
        print('我是橘子')
apple=Apple()
apple.harvest(apple.color)
orange=Orange()
orange.harvest(orange.color)

Fruit_2

class Fruit:
    def __init__(self,color='绿色'):
        Fruit.color=color
    def harvest(self,color):
        print('水果是:'+self.color+'的!')
        print('水果已经收获....')
        print('水果原来是:'+Fruit.color+'的!')
class Apple(Fruit):
    color='红色'
    def __init__(self):
        print("我是苹果")
        super().__init__()
class Sapodilla(Fruit):
    def __init__(self,color):
        print("\n我是人参果")
        super().__init__(color)
    def harvest(self,color):
        print('人参果是:'+color+'的!')
        print('人参果已经收获....')
        print('人参果原来是:'+Fruit.color+'的!')
apple=Apple()
apple.harvest(apple.color)
sapodilla=Sapodilla('白色')
sapodilla.harvest('金黄色带紫色条纹')

 

Project

#实战1
class Sj:
    _mr='英文'
    __sz='中文'
    def __init__(self):
        print('智能手机的默认语言为',Sj._mr)
        print('将智能手机的默认语言设置为',Sj.__sz)
sj=Sj()
#实战2
class Credit:
    def __init__(self,card,password='123456'):
        if password=='123456':
            print('信用卡',str(card),'的默认密码为',str(password))
        else:
            print('重置信用卡',str(card),'的默认密码为',str(password))    
            
Credit('36247675425645')
Credit('36247675425645','168779')
#实战3
class Sale:
    def __init__(self):
        self.__sale_date={'2':[('T0001','笔记本电脑'),('T0002','荣耀6X'),('T0003','ipad'),('T0004','荣耀V9'),('T0005','MACBook')]}
    def SaleList(self,value):
        if value in self.__sale_date:
            print('{}月份的商品销售明细如下:'.format(value))
            for item in self.__sale_date['2']:
                print('商品编号:%s商品名称:%s'%item)
        else:
            print('该月份没有销售数据或者输入月份有误!')
print('----------销售明细-----------')
sale=Sale()
while True:
    a=input('请输入要查询的月份(比如1,2,3等)')
    if a=='0':
        break
sale.SaleList(a)
#实战4
class ZiDong:
    
    def __init__(self):
        print('****欢迎使用自动售票机******')
        pass
    def select_film(self,films):
        film_1=films
        print('已选电影:',film_1)
        pass
    def select_time(self,times):
        time_1='2018.4.12'+times
        print('已选场次:'+time_1)
        pass
    def select_seat(self,seats):
        seat_1=seats
        print('选择座位:'+seat_1)
        pass

 

标签:Chapter,__,color,self,init,print,def
From: https://www.cnblogs.com/Kyaria-code-test/p/16978246.html

相关文章

  • Chapter 8
    Bmibmi.pydeffun_bmi(person,height,weight):print(person+'的身高'+str(height)+'米\t体重:'+str(weight)+'千克')bmi=weight/(height*height)print(perso......
  • Chapter 6
    Function_tipsdeffunction_tips():importdatetimemot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的......
  • Chapter 4
    Datetimeimportdatetime#定义一个列表mot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的人一定能笑着收获。",......
  • Chapter6_与数据结构称为好朋友的七个要点
    热身问答程序中的变量是指什么?变量是数据的容器。变量中所存储的数据是可以改变的。变量的实质是按照变量所存储数据的大小被分配到的一块内存空间。把若干个数据......
  • Chapter5_与算法成为好朋友的七个要点
    热身问答Algorithm翻译成中文是什么?算法辗转相除法是用于计算什么的算法?是用于计算最大公约数的算法。最大公约数指的是两个整数的公共约数中最大的数。使用辗转......
  • Chapter7_成为会使用面向对象编程的程序员吧
    理解面向对象编程热身问答Object翻译成中文是什么?对象对象(Object)是表示事物的抽象名词。OOP是什么的缩略语?ObjectOrientProgramming面向对象也可以简称......
  • Chapter8_一用就会的数据库
    热身回答数据库术语中的“表”是什么意思?table,表示数据的集合表(Table)就是被整理成表格形式的数据一张表由若干个列和行构成。列也被称为字段(Field),行也被称为记录(Re......
  • Chapter9_通过七个简单的实验理解TCP_IP网络
    热身问答LAN是什么的缩略语?LAN是LocalAreaNetwork(局域网)的缩略语。通常把在一栋建筑物内或是一间办公室里的那种小规模网络称作LAN。与此相对,把互联网那样......
  • Chapter11_XML究竟是什么
    热身回答XML是什么的缩写?Extensiblemarkuplanguage可扩展标记语言所谓标记语言,就是可以用标签为数据赋予意义的语言。HTML和XML的区别是什么?HTML是网页,X......
  • Chapter10_试着加密数据吧
    热身问答通常把还原加密过的文件这一操作叫作什么?解码解密在字母A的字符编码上加上3,可以得到哪个字母?D因为字母表中的字母编码是按字母顺序排列的,所以在字母......