-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18jun.py
More file actions
84 lines (77 loc) · 2.34 KB
/
18jun.py
File metadata and controls
84 lines (77 loc) · 2.34 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
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("---------- Details of c1 ----------")
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:")
self.name = input("Name: ")
self.price = int(input("Price: "))
self.fuel = input("Fuel: ")
# def displayDetails(self, something):
# print("Something is -", something)
c1 = Car("Elantra", 2500000, "Petrol")
# c1.displayDetails("Nothing")
c2 = Car("Verna", 1200000, "Petrol")
# c1.changeDetails()
# c1.displayDetails()
c3 = Car("Fortuner", 3500000, "Diesel")
"""
Press 1 - to add a new car
2 - display details of an existing car
3 - change details of an existing car
4 - delete a car
5 - exit
"""
# Your code goes here
while(1):
print("0 - display Srno. with name of car.")
print("1 - to add new Car.")
print("2 - display details of an existing car")
print("3 - change details of an existing car")
print("4 - delete a car")
print("5 - for exit")
choice = int(input("Enter a choice: "))
if choice == 0 :
print("Sr no.\tName")
for c in range(len(Car.allcars)):
print(f"{c}\t{Car.allcars[c].name}")
elif choice == 1:
pass
elif choice == 2:
n = input("Enter car name:")
if n == c1.name:
c1.displayDetails()
if n == c2.name:
c2.displayDetails()
if n == c3.name:
c3.displayDetails()
else:
print("There is no car exist.")
elif choice == 3 :
n = input("Enter car name:")
if n == c1.name:
c1.changeDetails()
if n == c2.name:
c2.changeDetails()
if n == c3.name:
c3.changeDetails()
else:
print("There is no car exist.")
elif choice == 4:
pass
elif choice == 5:
break
else :
print("Invalid choice...")