-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtual-car-shop.py
182 lines (152 loc) · 5.12 KB
/
virtual-car-shop.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Created 26 July 2017
# Definition for the class: Car
class Car(object):
# initialize your class attributes
carMaxPrice = 0
carMPG = 0
carType = ""
carName = ""
carCondition = ""
def __init__(self, name):
self.carName = name
# All the setter methods for this class
# Set Car Type
def setCarType(self, typeOption):
carTypeDict = {"1": "Convertible", "2": "Hybrid", "3" : "Sports Car"}
if carTypeDict.get(typeOption):
self.carType = carTypeDict[typeOption]
else:
self.carType = -1
# Set Condition
def setCarCondition(self, conditions):
conditionDict = {"1": "New", "2": "Pre-Owned"}
if conditionDict.get(conditions):
self.carCondition = conditionDict[conditions]
else:
self.carCondition = -1
# Set Price
def setPrice(self, price_range):
priceDict = { "1" : 40000, "2" : 50000 ,"3" : 100000}
if priceDict.get(price_range):
priceRange = priceDict[price_range]
self.carMaxPrice = priceRange
else:
self.carMaxPrice = -1
# Set MPG
def setMPG(self, mpg):
mpgDict = { "1" : 20 ,"2" : 30, "3" : 40}
if mpgDict.get(mpg):
self.carMPG = mpgDict[mpg]
else:
self.carMPG = -1
# All the getter methods for this class
# Get name
def getName(self):
return self.carName
# Get MPG
def getMPG(self):
return self.carMPG
# Get Price
def getPrice(self):
return self.carMaxPrice
# Get Condition
def getCarCondition(self):
return self.carCondition
# Get Car Type
def getCarType(self):
return self.carType
def carInventory(name, type, conditions, maxprice, mpg):
found = 0
typesDict = {
"Convertible" : ["Ford Mustang", "Mercedes SLK"],
"Hybrid" : ["Honda Civic", "Toyota Prius"],
"Composite" : ["Chevrolet Volt", "Tesla Model S"]
}
carDetailsDict = {
"Ford Mustang" : [25000, 25, "New", ["silver","blue","yellow","red"]],
"Mercedes SLK" : [48000, 30, "New", ["silver","white","black"]],
"Honda Civic" : [30000, 45, "New", ["slate grey","white"]],
"Toyota Prius" : [30000, 45, "New", ["baby blue","dark grey"]],
"Chevrolet Volt" : [35000, 100, "New", ["white","maroon"]],
"Tesla Model S" : [68000, 100, "New", ["black","deep blue"]],
}
carList = typesDict.get(type)
for car in carList:
details = carDetailsDict[car]
if details[0] <= maxprice:
if details[2] == conditions:
if details[1] >= mpg:
found += 1
print ("\n\nMatch found for: ", name)
print ("Car Make: ", car)
print ("MSRP USD: ", details[0])
print ("Condition:", details[2])
print ("MPG: ", details[1])
print ("Available colors: ", details[3])
if found == 0:
print ("Search criteria should be updated, no matches found for: ", name)
# Main starts here
print ('\n\n #### WELCOME!! to the NON-SLEAZY virtual car shop! ####\n\n')
# This will be used in a print statement to provide options to the user
# on car types he/she can pick from
car_options = """
Please pick the type of car you are interested in:
1. Convertible
2. Hybrid
3. Sports Car
"""
# This will be used in a print statement to provide options to the user on
# price ranges
price_ranges = """
1. < 40K
2. < 50K
3. < 100K
"""
# This will be used to ask whether the user wants a new or used car
condition = """
1. New
2. Pre-Owned
"""
# This section will be used to take a color input on your car
miles_per_gallon = """
1. 20 mpg
2. 30 mpg
3. 40 mpg
"""
carName = input("What would you like to call your car: ")
carType = input(car_options)
carCondition = input(condition)
carPriceRange = input(price_ranges)
carMPG = input(miles_per_gallon)
# Instantiate your car from the "Car" class
myCar = Car(carName)
# Set the type of car and the price range for the car
myCar.setCarType(carType)
myCar.setCarCondition(carCondition)
myCar.setPrice(carPriceRange)
myCar.setMPG(carMPG)
# Get the car name, price range and type of car
myCarName = myCar.getName()
myCarType = myCar.getCarType()
myCarCondition = myCar.getCarCondition()
myCarMax = myCar.getPrice()
myCarMpg = myCar.getMPG()
#
# Error Checking Code
if myCarType == -1:
print("Invalid type of car specified, exiting...")
exit(1)
if myCarCondition == -1:
print("Invalid car condition, exiting...")
exit(1)
if myCarMax == 0 or myCarMax == -1:
print("Invalid Price range specified for your car, exiting...")
exit(1)
if myCarMpg == 0 or myCarMpg == -1:
print("Invalid selection for MPG, exiting..")
exit(1)
#print ("My car is called: ", myCarName)
#print ("Car type selected: ", myCarType)
#print ("Maximum price range specified is: ", myCarMax)
#print ("Miles per gallon for %s is: %s mpg." %(myCarName, myCarMpg))
carInventory(myCarName, myCarType, myCarCondition, myCarMax, myCarMpg)