Question

In: Computer Science

id manufacturer model displ year cyl trans drv cty hwy fl class 1 audi a4 1.8...

id manufacturer model displ year cyl trans drv cty hwy fl class
1 audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
2 audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
3 audi a4 2 2008 4 manual(m6) f 20 31 p compact
4 audi a4 2 2008 4 auto(av) f 21 30 p compact
5 audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
6 audi a4 2.8 1999 6 manual(m5) f 18 26 p compact
7 audi a4 3.1 2008 6 auto(av) f 18 27 p compact
8 audi a4 quattro 1.8 1999 4 manual(m5) 4 18 26 p compact
9 audi a4 quattro 1.8 1999 4 auto(l5) 4 16 25 p compact
10 audi a4 quattro 2 2008 4 manual(m6) 4 20 28 p compact
11 audi a4 quattro 2 2008 4 auto(s6) 4 19 27 p compact
12 audi a4 quattro 2.8 1999 6 auto(l5) 4 15 25 p compact


Output file should contain the calculation output for: o Python code properly runs and calculates the average city mileage for all vehicles (avg_city) – 15 pts o Python code properly runs and calculates the average highway mileage for all vehicles (avg_hwy) – 15 pts o Python code properly runs and calculates the average highway mileage of all Ford vehicles (ford_hwy) – 20 pts o Python code properly runs and calculates the average city mileage of all SUV vehicles (suv_city) – 20 pts • Only iterate through mpg.csv once, minus 10 points for each loop through mpg.csv more than once

Solutions

Expert Solution

*****
student_name='Enter your name here'
paws_id='A123'#enter our paws id

sum_cty=0
n=0
sum_hwy=0
sum_ford_hwy=0
n_ford_hwy=0
sum_suv_city=0
n_suv_city=0

firstLine=True
with open('MPG.csv','r') as f:
for line in f:
if firstLine:
firstLine=False
else:
data=line.split(',')
sum_cty+=float(data[8])
sum_hwy+=float(data[9])
n=n+1
if data[1].lower()=='ford':
sum_ford_hwy+=float(data[9])
n_ford_hwy+=1
if data[-1].strip().lower()=='suv':
sum_suv_city+=float(data[8])
n_suv_city+=1

avg_city=sum_cty/n
avg_hwy=sum_hwy/n
ford_hwy=sum_ford_hwy/n_ford_hwy
suv_city=sum_suv_city/n_suv_city

f=open(paws_id+'_assignment4.txt','w')
f.write('Average city mileage for all vehicles: {:.4f}\n'.format(avg_city))
f.write('Average highway mileage for all vehicles: {:.4f}\n'.format(avg_hwy))
f.write('Average highway mileage of all Ford vehicles: {:.4f}\n'.format(ford_hwy))
f.write('Average city mileage of all SUV vehicles: {:.4f}\n'.format(suv_city))
f.close()


Related Solutions

Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
I. Create the class Item with the following members: 1. id, a protected variable of type...
I. Create the class Item with the following members: 1. id, a protected variable of type int 2. name, a protected variable of type string 3. price, a protected variable of type double 4. a public non-default constructor which accepts three parameters to initialize the variables above 5. a copy constructor 6. overload the = operator such that both operands are of type Item 7. overload the = operator such that the right operand is of type double. Assign the...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
I. Create the class Item with the following members:   1. id, a protected variable of type...
I. Create the class Item with the following members:   1. id, a protected variable of type int   2. name, a protected variable of type string   3. price, a protected variable of type double   4. a public non-default constructor which accepts three parameters to initialize the variables above II. Create the class Chair. The class publicly inherits from Item and has the following members   1. numLegs, a private variable of type int   2. a non-default constructor to initialize numLegs, id, name,...
An investor in Treasury securities expects inflation to be 1.8%in Year 1, 2.2% in Year...
An investor in Treasury securities expects inflation to be 1.8% in Year 1, 2.2% in Year 2, and 3.15% each year thereafter. Assume that the real risk-free rate is 1.75% and that this rate will remain constant. Three-year Treasury securities yield 5.20%, while 5-year Treasury securities yield 6.00%. What is the difference in the maturity risk premiums (MRPs) on the two securities; that is, what is MRP5 - MRP3? Do not round intermediate calculations. Round your answer to two decimal...
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement...
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement any necessary methods in addition to: a.The toString and equals methods. The equals method should NOT compare the id. b.The copy constructor (should copy the same id too) c.An abstract method float getWeeklyCheckAmount() d.Implement the appropriate interface to be able to sort employee names in alphabetical order. Subclasses should NOT be allowed to override this implementation. 2.Design an abstract class HourlyWorker that extends Employee...
Part 1: Create a Car class in accordance with the following specifications. make model year fuel...
Part 1: Create a Car class in accordance with the following specifications. make model year fuel tank size fuel economy – fuel economy at best speed optimal speed Some of the other fields: odometer trip odometer color fuel level The Car class will also need at least 3 constructors: Car() Car(String, String, String, int, double, double, double) Car(Car) The Car class must implement the following methods. public fillTank(double): double public toString():String public equals(Car):boolean public driveCar():boolean public getTripOdometer():double public clearTripOdometer():void public...
1-conctruct trans-1,2-dimethylcyclohexane.by means of ring flips, examine the model with the two-CH3 groups axial and the...
1-conctruct trans-1,2-dimethylcyclohexane.by means of ring flips, examine the model with the two-CH3 groups axial and the two -CH3 groups equatorial (e,e=equatorial,equatorial a,a=axial, axial) wich is more stable conformation ? explain the answer. Need part 2 of this 2-construct cis-1,2-dimethylcyclohexane by placing one-CH3 group axial and the other equatorial (a,e=axial, equatorial,e,a=equatorial,axial)Do rings flips and examine the 2 chair conformations. ( Explain wich is more stable)give the 2 isomers , trans-1-2-dimethylcyclohexane and cis-1,2-dimethycyclohexane, which is more stable isomers . Explain your answer.
1.       Choo Choo Inc. is a manufacturer of model trains. The company is considering the...
1.       Choo Choo Inc. is a manufacturer of model trains. The company is considering the purchase of an industrial 3D printer, which will allow the firm to produce custom-made model trains for its high-end customers. The printer will cost $2,500,000, and it is expected to produce net cash flows of $600,000 per year for the next six years. Liquidation of the equipment will net the firm $350,000 in cash at the end of six years. The firm requires a...
1.       Choo Choo Inc. is a manufacturer of model trains. The company is considering the...
1.       Choo Choo Inc. is a manufacturer of model trains. The company is considering the purchase of an industrial 3D printer, which will allow the firm to produce custom-made model trains for its high-end customers. The printer will cost $1,000,000, and it is expected to produce net cash flows of $350,000 per year for the next six years. Liquidation of the equipment will net the firm $100,000 in cash at the end of six years. The firm requires a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT