Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Cars’ Inventory

GENG 106 – Computer Programming Lab Project Report


General Engineering
Qatar University

Cars’ Inventory
___________________________________________________________

Report by
ENTER YOUR NAME HERE

Date
SELECT DATE OF SUBMISSION HERE

General Engineering GENG 106 – Computer Programming Lab Project Report i


Cars’ Inventory

DECLARATION STATEMENT
We, the undersigned students, confirm that the work submitted in this project report is entirely
our own and has not been copied from any other source. Any material that has been used from
other sources has been properly cited and acknowledged in the report.
We are fully aware that any copying or improper citation of references/sources used in this report
will be considered plagiarism, which is a clear violation of the Code of Ethics of Qatar University.
In addition, we have read and understood the legal consequences of committing any violation of
the Qatar University’s Code of Ethics.

Student Name Student ID Date


1
2
3

General Engineering GENG 106 – Computer Programming Lab Project Report ii


Cars’ Inventory

TABLE OF CONTENTS
Introduction iv
Project Plan iv
Python’s Code v
Output and validation xxiv
Conclusion xxvii

General Engineering GENG 106 – Computer Programming Lab Project Report iii
Cars’ Inventory

Introduction
This program is an inventory of car and its details. Due to the difficult to manage the manual data
while it’s getting larger we develop a program for it, which allow to add new car, update some
levels of information and print several reports.

This application was built in python and it’s designed to run in the terminal windows. The data of
the car is processed from a file given “cars.txt” and the application stored them in lists that allow a
fast access using the index of the car. Otherwise we can upload data to the file when we add a car,
or when we delete a specific car based on a characteristic. We can also print reports about the top
profit car, best performance between Highway miles per gallon and engine size, or a regression
line related to the engine size and the average miles per gallon.

Project Plan

# Task Responsible Hours


1-3 4-6 7-9 10-12 13-15 16-18 19-21
0 Save data in list
1 Add a New Car
2 Search a Car
3 Display certain cars
4 Display top profit cars
5 Delete Cars
6 Display top 3 cars with Mpg and
smallest engine size
7 Calculate the slope, intercept and
correlation
8 Plot the data
9 Adapt the exit option

Design Testing and Validation

General Engineering GENG 106 – Computer Programming Lab Project Report iv


Cars’ Inventory

Python’s Code
def validate_f(N):

#This Function validate that the input float number is neither negative nor zero

while (float(N)<=0.0):

N = input("\nInput the number again. Cannot be negative or zero\n")

return N

def validate_i(N):

#This Function validate that the input integer number is neither negative nor zero

while (int(N)<=0):

N = input("\nInput the number again. Cannot be negative or zero\n")

return N

def validate_b(N):

while (N != "0" and N != "1"):

N = input("\nInput the number again. Must be zero (0) or one (1) \n")

return N

def num_Lines (F):

#This Function calculate the number of lines of the file

try:

F.seek(0)

return len(F.readlines())

except AttributeError:

print ("Must insert a File")

return -1

def get_data(FILE,N):

#This Function gets the data from the file and split it based on the index of the character

#First we declare the lists

General Engineering GENG 106 – Computer Programming Lab Project Report v


Cars’ Inventory
Vehicle_Name = []

Sports_Car = []

Sports_Utility = []

Wagon = []

Minivan = []

Pickup = []

All_Wheel = []

Rear_Wheel = []

Retail_Price = []

Dealer_Cost = []

Engine_Size = []

Number_Cylinders = []

HP = []

City_MpG = []

Highway_MpG = []

Weight = []

Wheel_Base = []

Length = []

Width = []

f.seek(0)

for i in range (N):

line = f.readline()

#Based on the index the line is splitted

Vehicle_Name.append(line[0:45])

Sports_Car.append(line[46])

Sports_Utility.append(line[48])

Wagon.append(line[50])

Minivan.append(line[52])

Pickup.append(line[54])

All_Wheel.append(line[56])

Rear_Wheel.append(line[58])

Retail_Price.append(line[60:65])

Dealer_Cost.append(line[67:72])

General Engineering GENG 106 – Computer Programming Lab Project Report vi


Cars’ Inventory
Engine_Size.append(line[74:77])

Number_Cylinders.append(line[78:79])

HP.append(line[81:84])

City_MpG.append(line[85:87])

Highway_MpG.append(line[88:90])

Weight.append(line[91:95])

Wheel_Base.append(line[96:99])

Length.append(line[100:103])

Width.append(line[104:106])

return Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost, Engine_Size,
Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width

def download_data(FILE):

#This function update the data for the program based on the data downloaded from the file

f.seek(0)

Total_File = f.read()

Num_Lines = num_Lines (f)

Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost, Engine_Size, Number_Cylinders ,
HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = get_data(f,Num_Lines)

return Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width

def print_info_car (index):

#This function shows in screen the data of certain car, using its index to select the car

print(index)

print(".- Vehicle Name\n")

print(Vehicle_Name[index])

print("\nThe vehicule is a Sport Car?\n")

print(Sports_Car[index])

General Engineering GENG 106 – Computer Programming Lab Project Report vii
Cars’ Inventory
print("\nThe vehicle is a Sport Utility Vehicle? \n")

print(Sports_Utility [index])

print("\nThe vehicle is a Wagon? \n")

print(Wagon[index])

print("\nThe vehicle is a Minivan? \n")

print(Minivan[index])

print("\nThe vehicle is a Pickup? \n")

print(Pickup [index])

print("\nThe vehicle has All-Wheel drive? \n")

print(All_Wheel [index])

print("\nThe vehicle has Rear-Wheel drive? \n")

print(Rear_Wheel [index])

print("\nWhat is the Retail Price? \n")

print(Retail_Price [index])

print("\nWhat is the Dealer Cost? \n")

print(Dealer_Cost [index])

print("\nWhat size is the engine? \n")

print(Engine_Size [index])

print("\nHow many cylinders has the engine? If has a rotary engine appears -1 \n")

print(Number_Cylinders [index])

print("\nHow many Horsepower? \n")

print(HP [index])

print("\nHow many city miles per Gallon? \n")

print(City_MpG [index])

General Engineering GENG 106 – Computer Programming Lab Project Report viii
Cars’ Inventory

print("\nHow many highway miles per Gallon? \n")

print(Highway_MpG [index])

print("\nHow much does it weigh? \n")

print(Weight [index])

print("\nHow is the Wheel Base? \n")

print(Wheel_Base [index])

print("\nWhat length is? \n")

print(Length [index])

print("\nWhat width is? \n")

print(Width [index])

return 0

def bubblesort(List):

#This function is based on the algorithm bubblesort, which rearrange the list in growing order

n = len(List)

for i in range (1,n):

for j in range (n-i):

if (List [j] > List [j+1]):

List[j], List[j+1] = List[j+1], List [j]

return List

def add_a_car(f,New_Car_Input):

#This function add a car and its info to the file

#Calculate the length to then fill the missing spaces for the alignment

Len_Name = len(New_Car_Input[0])

Len_Retail = len(New_Car_Input[8])

General Engineering GENG 106 – Computer Programming Lab Project Report ix


Cars’ Inventory
Len_Dealer = len(New_Car_Input[9])

Len_Engine = len(New_Car_Input[10])

Len_Cylinders = len (New_Car_Input[11])

Len_HP = len(New_Car_Input[12])

Len_City_MpG = len(New_Car_Input[13])

Len_Highway_MpG = len(New_Car_Input[14])

Len_Weight = len(New_Car_Input[15])

Len_Wheel_Base = len(New_Car_Input[16])

Len_Length = len(New_Car_Input[17])

Len_Width = len(New_Car_Input[18])

f.seek(0,2)

f.write(New_Car_Input[0])

f.write(" "*(45-Len_Name))

f.write(" ")

f.write(New_Car_Input[1])

f.write(" ")

f.write(New_Car_Input[2])

f.write(" ")

f.write(New_Car_Input[3])

f.write(" ")

f.write(New_Car_Input[4])

f.write(" ")

f.write(New_Car_Input[5])

f.write(" ")

General Engineering GENG 106 – Computer Programming Lab Project Report x


Cars’ Inventory

f.write(New_Car_Input[6])

f.write(" ")

f.write(New_Car_Input[7])

f.write(" ")

f.write(New_Car_Input[8])

f.write(" "*(6-Len_Retail))

f.write(" ")

f.write(New_Car_Input[9])

f.write(" "*(6-Len_Dealer))

f.write(" ")

f.write(New_Car_Input[10])

f.write(" "*(3-Len_Engine))

f.write(" ")

f.write(New_Car_Input[11])

f.write(" "*(2-Len_Cylinders))

f.write(" ")

f.write(New_Car_Input[12])

f.write(" "*(3-Len_HP))

f.write(" ")

f.write(New_Car_Input[13])

f.write(" "*(2-Len_City_MpG))

f.write(" ")

General Engineering GENG 106 – Computer Programming Lab Project Report xi


Cars’ Inventory
f.write(New_Car_Input[14])

f.write(" "*(2-Len_Highway_MpG))

f.write(" ")

f.write(New_Car_Input[15])

f.write(" "*(4-Len_Weight))

f.write(" ")

f.write(" "*(3-Len_Wheel_Base))

f.write(New_Car_Input[16])

f.write(" ")

f.write(New_Car_Input[17])

f.write(" "*(3-Len_Length))

f.write(" ")

f.write(New_Car_Input[18])

f.write(" "*(2-Len_Width))

f.write("\n")

return 0

def Input_a_Car():

#This function read a car and its info from the user and upload it to the file

print ("Input the car data requested \n For dicotomics questions 1 represent YES, and 0 represent NO \n\n")

New_Car_Name = input ("What is the Name of the Car? \n")

New_Sports_Car = validate_b(input("Is The vehicle a Sport Car? \n"))

New_Sports_Utility = validate_b(input ("Is The vehicle a Sport Utility Vehicle? \n"))

New_Wagon = validate_b(input ("Is The vehicle a Wagon? \n"))

New_Minivan = validate_b(input ("Is The vehicle a Minivan? \n"))

New_Pickup = validate_b(input ("Is The vehicle a Pickup? \n"))

New_All_Wheel = validate_b(input ("Has The vehicle All-Wheel drive? \n"))

General Engineering GENG 106 – Computer Programming Lab Project Report xii
Cars’ Inventory
New_Rear_Wheel = validate_b(input ("Has The vehicle Rear-Wheel drive? \n"))

New_Retail_Price = validate_f(input ("What is the Retail Price? \n"))

New_Dealer_Cost = validate_f(input ("What is the Dealer Cost? \n"))

New_Engine_Size = validate_f(input ("What size is the engine? \n"))

New_Number_Cylinders = input ("How many cylinders has the engine? If has a rotary engine input -1 \n")

New_HP = validate_i(input ("How many Horsepower? \n"))

New_City_MpG = validate_i(input ("How many city miles per Gallon? \n"))

New_Highway_MpG = validate_i(input ("How many highway miles per Gallon? \n"))

New_Weight = validate_f(input ("How much does it weigh? \n"))

New_Wheel_Base = validate_i(input ("How is the Wheel Base? \n"))

New_Length = validate_i(input ("What length is? \n"))

New_Width = validate_i(input ("What width is? \n"))

New_Car_Input = [New_Car_Name, New_Sports_Car, New_Sports_Utility, New_Wagon, New_Minivan, New_Pickup, New_All_Wheel,


New_Rear_Wheel, New_Retail_Price, New_Dealer_Cost, New_Engine_Size, New_Number_Cylinders, New_HP, New_City_MpG, New_Highway_MpG,
New_Weight, New_Wheel_Base, New_Length, New_Width]

add_a_car(f,New_Car_Input) # third parameter in zero because this one is not the first car

return 0

def delete_car(index):

#This function delete a car based on its index, also deletes all of its info

Vehicle_Name.pop(index)

Sports_Car.pop(index)

Sports_Utility.pop(index)

Wagon.pop(index)

Minivan.pop(index)

Pickup.pop(index)

All_Wheel.pop(index)

Rear_Wheel.pop(index)

Retail_Price.pop(index)

Dealer_Cost.pop(index)

Engine_Size.pop(index)

General Engineering GENG 106 – Computer Programming Lab Project Report xiii
Cars’ Inventory
Number_Cylinders.pop(index)

HP, City_MpG.pop(index)

Highway_MpG.pop(index)

Weight.pop(index)

Wheel_Base.pop(index)

Length.pop(index)

Width.pop(index)

return 0

def upload_data (f, Total_Data, N):

#This Function upload the data from the program to the file, rewritting it since the beginning

f.close()

f = open("cars.txt","w") #We open the file in write mode to overwrite it

New_Car = []

for i in range(len(Total_Data[0])):

for j in range(len(Total_Data)):

New_Car.append(Total_Data[j][i])

add_a_car(f,New_Car)

New_Car = []

f.close()

f = open("cars.txt","r+") #Finally we reopen the file in the r+ mode to be able to read and write in it

return f

def Slo_Int_Corr(Engine_Size,Highway_MpG,City_MpG):

#This function calculates the slope, the interception and the correlative from 2 info list

#return the X, Y info list, and the 3 calculations named before

General Engineering GENG 106 – Computer Programming Lab Project Report xiv
Cars’ Inventory
X = []

Y = []

for i in range(len(Engine_Size)):

X.append(float(Engine_Size[i]))

Average = (float(Highway_MpG[i]) + float(City_MpG[i]))/2

Y.append(Average)

SumX, SumY, SumXY = 0.0 , 0.0, 0.0

SumXsquared, SumYsquared = 0.0 , 0.0

N = len(X)

for i in range(N):

SumX = SumX + X[i]

SumY = SumY + Y[i]

SumXY = SumXY + (X[i]*Y[i])

SumXsquared = SumXsquared + X[i]*X[i]

SumYsquared = SumYsquared + Y[i]*Y[i]

Slope = (N*SumXY - (SumX*SumY))/(N*SumXsquared - SumX**2)

Intercept = (SumY - (Slope*SumX))/N

Corr = (N*SumXY - (SumX*SumY))/ (((N*SumXsquared - SumX**2)*(N*SumYsquared - SumY**2))** 0.5)

return X, Y, Slope, Intercept, Corr

General Engineering GENG 106 – Computer Programming Lab Project Report xv


Cars’ Inventory

f = open("cars.txt","r+")

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost, Engine_Size,
Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

f.seek(0)

print (Total_File)

option = 0

option_seven = False #This command allows us to know if the program has done the section 7 and its calculations

while(option != 9):

print("""

Menu

1. Add a New Car

2. Search for a car by its name

3. Display all sport cars that has Rear-Wheel Drive, and engine zise is greater than 3

4. Display Top 10 cars that makes best profit

5. Delete all Minivan Cars

6. Display Top 3 cars has best Highway Miles per Gallon and smallest Engine size

7. Calculate the Slope and intercept of a linear regression and correlation between the x and the y data

8. Plot the calculated regression line through the data in section 7

9. Exit

""")

option = int (input (" \nPlease select an option from above \n"))

option = validate_i(option)

if (option == 1):

General Engineering GENG 106 – Computer Programming Lab Project Report xvi
Cars’ Inventory

#We recieve a car and its info from the user and writr it in the file and then update the lists in the program

Input_a_Car()

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

print(Total_File);

elif (option == 2) :

#First we update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

#Ask for a name and complete its empty spaces to try to find a match with the existent car´s list

SN = input ("What is the name of the car you are looking for? \n");

Search_Name = (SN + " "*(45-len(SN)))

if (Search_Name in Vehicle_Name):

for i in range (Num_Lines):

if (Search_Name == Vehicle_Name[i]):

index = i

print_info_car (index) #If we find a match, we print the car and its info

else:

print("The car is not found")

elif (option == 3):

General Engineering GENG 106 – Computer Programming Lab Project Report xvii
Cars’ Inventory

#First we update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

#We try to find the top cars with Rear Wheel Drive and Engine size biggest than 3.0

#Save the index of each car that fulfill each condition and then compare

#to get the match index and print the cars and its info

if ("1" in Rear_Wheel):

index_Rear = []

index_Engine = []

index_P = []

for i in range(len(Rear_Wheel)):

if ("1" == Rear_Wheel[i]):

index_Rear.append(i)

print(index_Rear)

for i in range(len(Engine_Size)):

if (float(Engine_Size[i]) > 3.0 ):

index_Engine.append(i)

for j in range(len(index_Rear)):

for n in range (len(index_Engine)):

if (index_Rear [j] == index_Engine [n]):

index_P.append(index_Rear[j])

for k in range(len(index_P)):

General Engineering GENG 106 – Computer Programming Lab Project Report xviii
Cars’ Inventory
print_info_car (index_P[k])

print("\n\n\n\n\n\n\n\n\n\n")

else:

print ("\nAny car fulfill the conditions\n")

elif (option == 4):

#First we update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

#Declare the Lists

profit = []

profit_Og = []

for i in range (len(Retail_Price)):

prof = float(Retail_Price[i]) - float(Dealer_Cost[i])

profit_Og.append(float(prof))

profit.append(float(prof))

#Organize the profit list in growing order

profit = bubblesort(profit)

index_top_profit = [];

#We find the index of the 10 best cars´ proft

for i in range (10):

General Engineering GENG 106 – Computer Programming Lab Project Report xix
Cars’ Inventory
for j in range(len(profit_Og)):

if (float(profit_Og[j]) == (float(profit[-1-i]))): #we run profit[] from the end to the beginning to get the top 10

index_top_profit.append(j);

print(index_top_profit);

for k in range(10):

print("Profit = " + str(profit[-1-k]) );

print_info_car(index_top_profit[k]);

print("\n\n\n\n\n\n\n\n\n\n");

elif (option == 5 ):

#First we update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

index_minivan = []

#We get the index of the minivan cars to delete it an reorder the data lists

for i in range(len(Minivan)):

if ("1" == Minivan [i]):

index_minivan.append(i)

index_minivan.reverse() #We must delete since the beginning

for j in range(len(index_minivan)):

delete_car(index_minivan[j])

Total_Data_Car = [Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost, Engine_Size,
Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width]

General Engineering GENG 106 – Computer Programming Lab Project Report xx


Cars’ Inventory

#Upload the new data to the file and then update the data in the program

f = upload_data(f, Total_Data_Car, Num_Lines)

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

print (Total_File)

elif (option ==6):

#First we update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

Top_Highway = []

Smallest_Engine = []

#We proceed to reorder the Highway and the Engine Size Lists

Top_Highway = Highway_MpG[:]

Smallest_Engine = Engine_Size[:]

Top_Highway = bubblesort(Top_Highway)

Top_Highway.reverse()

Smallest_Engine = bubblesort(Smallest_Engine)

index_top_HW = []

index_smallest_engine = []

#We find the index of the Car with Top Highway Miles per Gallon

General Engineering GENG 106 – Computer Programming Lab Project Report xxi
Cars’ Inventory
for i in range(len(Top_Highway)):

for j in range(len(Highway_MpG)):

if (Top_Highway [i] == Highway_MpG [j]):

if ((j in index_top_HW)== False):

index_top_HW.append(j)

#We find the index of the Car with Smallest Engine

for i in range(len(Smallest_Engine)):

for j in range(len(Engine_Size)):

if (Smallest_Engine [i] == Engine_Size [j]):

if ((j in index_smallest_engine)== False):

index_smallest_engine.append(j)

sum_index = []

#We took the sum of the index in the top to know which car has best performance

for i in range(len(index_top_HW)):

S = index_top_HW.index(i) + index_smallest_engine.index(i)

sum_index.append(S)

top_sum = sorted(sum_index)

index_top_sum = []

for i in range(len(top_sum)):

for j in range(len(sum_index)):

if (top_sum [i] == sum_index [j]):

index_top_sum.append(j)

#Finally we print the top 3 cars with best performance in both aspects

for i in range(0,3):

print_info_car (index_top_sum[i])

print("\n\n\n\n\n\n\n\n\n")

General Engineering GENG 106 – Computer Programming Lab Project Report xxii
Cars’ Inventory

elif (option == 7):

option_seven = True #This Command indicates that we got in the section 7 at least one time

#We update the data lists from the file

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

X = []

Y = []

X, Y, Slope, Intercept, Corr = Slo_Int_Corr(Engine_Size,Highway_MpG,City_MpG)

print ("Slope = " + str(Slope))

print ("Intercept = " + str(Intercept))

print ("Correlation = " + str(Corr))

elif (option == 8):

Total_File, Num_Lines, Vehicle_Name, Sports_Car, Sports_Utility, Wagon, Minivan, Pickup, All_Wheel, Rear_Wheel, Retail_Price, Dealer_Cost,
Engine_Size, Number_Cylinders , HP, City_MpG, Highway_MpG, Weight, Wheel_Base, Length, Width = download_data (f)

if (option_seven == False):

print("\n\nYou need to calculate the slope and the intercept of the linear regression in section 7\n\n")

#This section requires to go through section 7 at least one time

else:

import matplotlib.pyplot as plt

import numpy as np

X = []

Y = []

X, Y, Slope, Intercept, Corr = Slo_Int_Corr(Engine_Size,Highway_MpG,City_MpG)

General Engineering GENG 106 – Computer Programming Lab Project Report xxiii
Cars’ Inventory
#Create the lists x,y of points to plot from the lists X,Y

x = np.array(X)

y = np.array(Y)

#Calculate the slope and the interception tu use in the plot

m,b = np.polyfit(x,y,1)

#plot the pair of points

plt.plot(x,y,"o")

#Add info to the graph and plot the regression line

plt.plot(x, m*x + b)

plt.title("Linear Regression")

plt.xlabel("Engine Size")

plt.ylabel("Average Miles per Gallon")

print ("Correlation = " + str(Corr))

plt.show()

Output and Validation

Also we have the output for each option

General Engineering GENG 106 – Computer Programming Lab Project Report xxiv
Cars’ Inventory

Figura 1 Menu Principal

If we select option 1 it allow us to input a new car, asking for each characteristics to include it in
the file.

For the option 2, ask us for the name of the car, and then complete the blank spaces to find a
match, and then return all the info of that specific car if it exists in the inventory. Then show us the
menu again, to select a new option.

Figura 2 Option 3. Search a car by its name

General Engineering GENG 106 – Computer Programming Lab Project Report xxv
Cars’ Inventory

Figura 3 Continuation Option 2

Figura 4 Continuation Option 2

In the option 3, the application print tall the cars that has Rear-Wheel Drive and engine size
greater than 3. For that the program verify the condition about Rear-Wheel Drive and verify
engine size greater than 3.0, then compare both results to evaluate which cars fulfill both
condition to finally print these cars.

To the option 4, the program calculates the profit of each cars, (Retail Price minus Dealer Cost) ,
reorder the list to get the top 10 by its index and then return the cars corresponding to each index
in the order pre-established. Then the menu is shown.

When the option 5 is selected, the program evaluate the condition “Minivan” to see if the car is a
minivan, and if fulfill the condition, save the index to further use. Finally, delete all the cars
corresponding to the previous index and then show the menu again

General Engineering GENG 106 – Computer Programming Lab Project Report xxvi
Cars’ Inventory
In the option 6, The application reorder the lists “Highway MpG” in descending order and “Engine
size” in growing order. Then take each car´ sum of the indexes of both list, to get the best
performance in both list. The top 3 cars with the best performance are print on the screen.

For the option 7, the program use the data of the list “Engine Size” and “Average MpG”. The
program calculate the average miles per gallon (MpG) for each car ((Highway MpG + City MpG)/2),
and reorder the index of the cars based on the top average MpG´s list order. Then use these data
as X and Y to calculate the slope, the interception and the correlation of the regression line.

Figura 5 Option 7. Calculations for the regression line

In the option 8, is necessary to go first through the section 7, to get the information for the graph.
We use the matplotlib python´s library to plot the data and the regression line and show it on the
screen. Also show the correlation factor.

Figura 6 Option 8. Plot the Calculated data in section 7

General Engineering GENG 106 – Computer Programming Lab Project Report xxvii
Cars’ Inventory

Figura 7. Linear Regression Graph

Conclusion
This project handle very well all the steps asked, and show the information clearly and easy to
read, because before each information show the name of that info or the relation with a main
subject.

Is important to accurate that the use of list and function ease the development of the program,
due to the easy access and organization of the information, accessing to them using the name of
the list and the index of the car we want to access. Also the facility given by the function to do
several action only by call them in a line, or the fast process to make one function which
implement another or avoiding us to rewrite a process by making it a function, another plus of the
use of both elements is that these make the code more readable for developers.

General Engineering GENG 106 – Computer Programming Lab Project Report xxviii

You might also like