-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path13-inheritance.py
71 lines (60 loc) · 2.11 KB
/
13-inheritance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Vehicle:
def __init__(self, model, wheel, engine, mileage):
self.model = model
self.no_of_wheels = wheel
self.engine_power = engine
self.mileage = mileage
def model_name(self):
return f"This is {self.model},"
def wheels(self):
if self.no_of_wheels == 2:
say = "a bike."
elif self.no_of_wheels == 4:
say = "a car."
else:
say = "a commercial vehicle."
return say
def details(self):
return f"Specs are: engine -> {self.engine_power} HP, mileage -> {self.mileage} KMPL."
class Bike(Vehicle):
# def __init__(self, model, wheel : int, engine : int, mileage : int):
def about_bike(self):
about = f"{self.model_name()} {self.wheels()} {self.details()}"
return about
class Car(Vehicle):
def about_car(self):
about = f"{self.model_name()} {self.wheels()} {self.details()}"
return about
class Commercial(Vehicle):
def about_commercial(self):
is_truck = input("Is it a truck: (T)rue / (F)alse : ")
if is_truck.lower() == 't':
say = "Welcome to your lorry ! here is more about it...\n"
return F"{say}{self.model_name()} {self.wheels()} {self.details()} "
else:
say = "Sorry! Currently we accept 'truck' only."
return f"{say} "
hero_hf = Bike("HF Delux", 2, 97, 70)
swift = Car("Swift_Desire", 4, 400, 23)
volvo = Commercial("Volvo TMS5", 8, 1080, 12)
# print(hero_hf.about_bike())
# print(volvo.about_commercial())
welcome_message = "\n$$$ Welcome to 'FindWheel' $$$"
while True:
print(welcome_message)
to_use = int(input("""Please have a look and choose :
1 -> Bike
2 -> Car
3 -> Commercial Vehicle
0 -> exit \nI want > """))
if to_use == 1:
print(hero_hf.about_bike())
elif to_use == 2:
print(swift.about_car())
elif to_use == 3:
print(volvo.about_commercial())
elif to_use == 0:
print("Thanks for visiting us! Please do come again🤗 ")
break
else:
print("\nInvalid wish! Please type 1, 2, 3 or 0 ")