Skip Navigation
home / study / engineering / computer science / computer science questions and answers / python...
Question: Python Programming This assignment will give you practice with interactive programs, if/else stat...
Python Programming
This assignment will give you practice with interactive programs, if/else statements, collections, loops and functions.
Problem Description
A small car yard dealing in second hand cars needs an application to keep records of cars in stock. Details of each car shall include registration(rego), model, color, price paid for the car (i.e. purchase price) and selling price. Selling price is calculated as purchased price plus mark-up of 30%. For example, Toyota Corolla bought for $20,000 will have the selling price of 20000 * (1 + 0.3) = 26000.
Task Requirements
Imagine you have been invited to develop a menu driven python application to manage records of cars in stock. Based on the problem description, starter program (code template) has been provided. Investigate the provided starter program. There are four scripts(application.py, caryard.py, cars.py and vehicle.py). Driver function(main) is defined in the appliction.py, which imports caryard module(caryard.py). Caryard declares all the core functions (buy, sell, search, etc. …) for supporting the car yard business. The caryard module imports cars module(cars.py), and the cars module in turn imports the vehicle that include a definition of a Car class.
Program is executed by loading and running the application.py. The important work of interconnecting and wiring of modules and functions have been already been done. However, most of these functions, although declared and wired up in the program are not yet implemented. Your task is to implement these functions. There are eleven (11) tasks to be completed described next within the modules:
1. application.py
• Task 1: implement menu ()
2. caryard.py
• Task 2: implement buy_car ()
• Task 3: implement sell_car ()
• Task 4: implement search_car ()
• Task 5: implement list_all_cars ()
3. cars.py
• Task 6: implement addCar (rego, model, color, price)
• Task 7: implement removeCar (rego)
• Task 8: implement all_cars ()
• Task 9: implement search(rego)
4. vehicle.py
• Task 10: implement the Car class
• Task 11: UML model of a Car class
Description of Program functions:
Program displays a menu on execution. Five menu options are available to allow the user to buy, sell, search, show all cars, and exit program respectively. XXXXXXX functionality and XXXXXX XXXXXX for XXXX XX the menu XXXXXX when XXXXXXXX XX XXX user XXXXXXX:
Program XXXX on XXXXXXXXX:
XXXXXX 1 (Buy a XXX): User XXXXXX 1. XXXX XXX XXXXX XXXXXXX for duplicate XXX XXXX
XXXXXX 2 (Sell a XXX): User enters X. Note XXX error XXXXXXX for XXXXXXX car rego, and the XXXX XXXXX which is a (XX%) mark-XX of purchase XXXXX.
XXXXXX X (Search): User XXXXXX X
Option 4 (Show XXX): User enters X
Option 5 (Exit XXXXXXX): XXXX enters X
XXXXXX Answer
Anonymous
Anonymous
answered XXXX
'''
Python XXXXXXX : 2.X
Python program XX create a car XXXXX
'''
XXXXX Car:
def __init__(self, XXXX, model, color, purchase_price):
self.rego = XXXX
self.model = model
self.XXXXX = color
XXXX.purchase_price = purchase_price
XXXX.selling_price = XXXX.XXXXXXXXXXXXXX*(1+0.X)
XXX XXXXXXX(XXXX):
XXXXXX('XXXXXXXXXXXX : %s Model: %s XXXXX : %s Purchase Price : $%.XX Selling Price : $%.2f' %(XXXX.rego, XXXX.model, self.XXXXX, self.purchase_price, self.XXXXXXXXXXXXX))
def XXXXXXXX(self):
XXXXXX('XXXXXXXXXXXX : %s Model: %s XXXXX : %s Purchase Price : $%.XX Selling Price : $%.2f' %(XXXX.rego, self.XXXXX, self.color, self.XXXXXXXXXXXXXX, self.selling_price))
XXX get_rego(XXXX):
XXXXXX XXXX.rego
XXX XXXXXXXXX(self):
XXXXXX self.model
XXX get_color(XXXX):
XXXXXX XXXX.XXXXX
def get_purchase_price(self):
return self.purchase_price
XXX XXXXXXXXXXXXXXXXX(XXXX):
return XXXX.XXXXXXXXXXXXX
XXX set_rego(XXXX, rego):
self.rego = rego
def XXXXXXXXX(XXXX):
self.XXXXX = model
XXX set_color(self,color):
XXXX.color = XXXXX
XXX XXXXXXXXXXXXXXXXXX(self,XXXXXXXXXXXXXX):
self.purchase_price = XXXXXXXXXXXXXX
self.selling_price = self.purchase_price(X+0.3)
#XXX XX vehicle.py
Code Screenshot:
XXXXXX XXXXXXX: 2.7 XXXXXX program to XXXXXX a car XXXXX X XXXXXX XXX: XXXX def init (XXXX, XXXX, model, color, purchase_pric
. XX XXX set XXXXX (XXXX): XXXX.model = XXXXX Ó XX XXX set XXXXX (XXXX, color): self.XXXXX = color X X 44 45 def set_purchase
'''
Python XXXXXXX : X.X
XXXXXX XXXXXXX to XXXXXX XXXXXXXXX to XXXXXX XXX list XX XXXX
'''
from XXXXXXX import XXX
def addCar(XXXX, model, XXXXX, price, XXXXXXX):
XXX = search(XXXX,carList)
if(XXX == -1):
carList.append(XXX(rego,model,color,price))
return XXXX
XXXXXX XXXXX
XXX removeCar(XXXX,XXXXXXX):
XXX = search(rego,XXXXXXX)
XX(XXX != -1):
XXX = carList.XXX(idx)
return car
else:
XXXXXX None
XXX all_cars(XXXXXXX):
XX(XXX(carList) == X):
XXXXX('No cars XXXXXXX')
else:
for car in XXXXXXX:
print(XXX)
XXX search(rego,carList):
XXX i in XXXXX(len(carList)):
if carList[i].XXXXXXXX() == XXXX:
XXXXXX i
XXXXXX -X
#XXX of cars.py
Code XXXXXXXXXX:
זזים Python version : 2.7 Python program to create functions to manage XXX XXXX of XXXX from XXXXXXX import Car 8 Ędef addCar
'''
Python XXXXXXX : X.7
Python XXXXXXX to XXXXXX XXXX options XXX the XXXX
'''
import XXXX
def XXXXXXX(XXXXXXX):
XXXX = raw_input('XXXXXXXXXXXX XXXXXX : ')
model = XXXXXXXXX('XXXXX : ')
color = raw_input('Color : ')
purchase_price = XXXXX(XXXXXXXXX('XXXXXXXX price : $'))
if(XXXX.XXXXXX(XXXX,XXXXX,XXXXX,purchase_price,XXXXXXX)):
XXXXX('Car with XXXXXXXXXXXX : %s XXXXXXX XXXXXX' %(XXXX))
def sell_car(carList):
rego = raw_input('XXXXXXXXXXXX Number : ')
XXX = cars.XXXXXXXXX(XXXX,carList)
XX(XXX == None):
print("Car with registration : %s XXXXX't XXXXXX" %(rego))
XXXX:
print("XXX XXXX at price : %.XX" %(XXX.get_selling_price()))
def XXXXXXXXXX(XXXXXXX):
rego = raw_input('XXXXXXXXXXXX XXXXXX : ')
idx = cars.XXXXXX(XXXX,carList)
if(idx != -1):
XXXXX(carList[XXX])
else:
XXXXX("Car XXXX registration : %s XXXXX't XXXXXX" %(XXXX))
def XXXXXXXXXXXXX(XXXXXXX):
cars.all_cars(carList)
#end XX caryard.py
XXXX Screenshot:
XX Python XXXXXXX : 2.X XXXXXX program XX create menu XXXXXXX XXX XXX main import XXXX ç XXX buy_car (carList): OUWDOO JOU XX
'''
XXXXXX version : 2.X
XXXXXX program XX XXXXXX the XXXX application
'''
import caryard
XXX main():
XXXXXXX = []
XXXXXX = X
XXXXX XXXXXX != X:
print('1. Buy a XXX')
XXXXX('2. Sell a XXX')
print('3. Search XXX a Car')
print('4. Show all cars')
print('5. Exit')
choice = XXX(XXXXXXXXX('Enter your choice : '))
XX XXXXXX == X:
XXXXXXX.XXXXXXX(carList)
XXXX XXXXXX == 2:
XXXXXXX.XXXXXXXX(XXXXXXX)
XXXX XXXXXX == 3:
caryard.XXXXXXXXXX(XXXXXXX)
elif XXXXXX == 4:
caryard.list_all_cars(XXXXXXX)
XXXX XXXXXX != X:
print('XXXXXXX choice')
XXXXX('')
print('XXX!')
main()
#end of application.py
XXXX XXXXXXXXXX:
X Python XXXXXXX : 2.7 Python XXXXXXX XX create XXX XXXX XXXXXXXXXXX import caryard 8 Edef main(): XXXXXXX = [] choice = X 1
Output:
1. Buy a Car 2. Sell a Car 3. XXXXXX for a Car X. Show all XXXX X. Exit XXXXX your XXXXXX : 4 No XXXX present 1. XXX a XXX 2.
X. XXX a XXX X. Sell a XXX X. Search for a Car 4. Show all XXXX X. XXXX Enter your choice : X Registration Number : car3 Car
Car XXX:
Car XXXX :string - XXXXX: XXXXXX XXXXX: string - XXXXXXXX price : float XXXXXXX price : XXXXX + get_rego(): XXXXXX + get XXXX
">