print("租用%s的天數是%d,**是%d" % (self.name, self.days, 600 * self.days))
class bwm(car):
def __init__(self, name, days):
super().__init__(name)
self.days = days
def price(self):
print("租用%s的天數是%d,**是%d" % (self.name, self.days, 500 * self.days))
# 紅旗1
class hongq(car):
def __init__(self, name, days):
super().__init__(name)
self.days = days
def price(self):
print("租用%s的天數是%d,**是%d" % (self.name, self.days, 300 * self.days))
# 金盃 <= 16人
class jinbei(car):
def __init__(self, name, days):
super().__init__(name)
self.days = days
def price(self):
print("租用%s的天數是%d,**是%d" % (self.name, self.days, 800 * self.days))
# 金龍 > 16人
class jinglong(car):
def __init__(self, name, days):
super().__init__(name)
self.days = days
def price(self):
print("租用%s的天數是%d,**是%d" % (self.name, self.days, 1500 * self.days))
def main():
flag = true
while flag:
print("*" * 30)
print("請選擇車型:")
print("1.小型車(4人座)")
print("2.大型客車(4人以上)")
size = int(input("請輸入1/2:"))
if size == 1:
print("*" * 30)
print("請選擇車型:")
print("1.別克gl8,600/天")
print("2.寶馬550i,500/天")
print("3.紅旗1,300/天")
sizecar = int(input("請選擇車型1/2/3:"))
days = int(input("請輸入使用天數:"))
if sizecar == 1:
c = bieke("別克gl8", days)
c.price()
elif sizecar == 2:
c = bwm("寶馬550i", days)
c.price()
elif sizecar == 3:
c = hongq("紅旗1", days)
c.price()
else:
print("輸入有誤~")
continue
elif size == 2:
print("*" * 30)
print("請選擇車型:")
print("1.金盃,16人及以下,800/天")
print("2.金龍,16人以上,1500/天")
sizecar2 = int(input("請選擇車型1/2:"))
days2 = int(input("請輸入使用天數:"))
if sizecar2 == 1:
c = jinbei("金盃", days2)
c.price()
elif sizecar2 == 2:
c = jinglong("金龍", days2)
c.price()
else:
print("輸入有誤~")
continue
else:
print("輸入有誤~")
continue
if __name__ == "__main__":
main()
介面 多型練習題
輸出下面程式結果 inte ce a class bimplements a class demo 執行結果 the method func is undefined for the type a 分析 a a new b 實現了多型,此時父類的引用指向子類的物件,相當於 動物 a new 狗 這就...
python書中練習題 python練習題
1 定義乙個空列表,接收從鍵盤輸入的整數,把列表傳給乙個從大到小排序的函式,再輸出排序後的列表的值 listex b 0 a int input 請輸入列表長度 while b a num int input 請輸入字元 b 1 print listex sum 0 for i in range 0...
python的練習題 Python練習題
1 使用while迴圈輸入1 2 3 4 5 6 8 9 10 i 0while i 10 i i 1 if i 7 continue print i 結果 e python python python test.py1 2 求1 100的所有數的和 i 0sum 0 while i 100 i 1...