-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18junhw.py
More file actions
88 lines (70 loc) · 2.24 KB
/
18junhw.py
File metadata and controls
88 lines (70 loc) · 2.24 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Car:
seating_capacity = 5 # class variable
allCars = []
def __init__(self, name, price, fuel):
self.name = name
self.price = price
self.fuel = fuel
Car.allCars.append(self)
# creating a method
def displayDetails(self):
print(f"---------- Details of {self.name} ----------")
print("Model Name:", self.name)
print("Price:", (self.price))
print("Fuel:", self.fuel)
print("Seating Capacity:", self.seating_capacity)
print()
def changeDetails(self):
print("Enter new details (just press Enter if you want to keep that detail same):")
n = self.name
p = self.price
f = self.fuel
self.name = input("Name: ")
if self.name == "":
self.name = n
self.price = input("Price: ")
if self.price == "":
self.price = p
self.fuel = input("Fuel: ")
if self.fuel == "":
self.fuel = f
# static methods
@staticmethod
def showAllCars():
print("Sr.No.\tName")
for i in range(len(Car.allCars)):
print(f"{i}\t{Car.allCars[i].name}")
# class method:
@classmethod
def addNewCar(cls):
print("Enter the following details:")
name = input("Name: ")
price = int(input("Price: "))
fuel = input("Fuel: ")
return cls(name, price, fuel)
c1 = Car("Elantra", 2500000, "Petrol")
c2 = Car("Verna", 1200000, "Petrol")
c3 = Car("Fortuner", 3500000, "Diesel")
while True:
print("Press:")
print("1 to add new car")
print("2 to display details of an exisiting car")
print("3 to change details of an exisiting car")
print("4 to delete an exisiting car")
print("5 to exit")
op = int(input())
if op == 1:
Car.addNewCar()
elif op == 2:
Car.showAllCars()
c = int(input("Sr.No:"))
Car.allCars[c].displayDetails()
elif op == 3:
Car.showAllCars()
c = int(input("Sr.No:"))
Car.allCars[c].changeDetails()
elif op == 4:
Car.showAllCars()
c = int(input("Sr.No:"))
Car.allCars.pop(c)
pass