1. 程式人生 > 其它 >Chapter 7

Chapter 7

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