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...

Free

80.2K

Verified Solution

Question

Programming

idmanufacturermodeldisplyearcyltransdrvctyhwyflclass
1audia41.819994auto(l5)f1829pcompact
2audia41.819994manual(m5)f2129pcompact
3audia4220084manual(m6)f2031pcompact
4audia4220084auto(av)f2130pcompact
5audia42.819996auto(l5)f1626pcompact
6audia42.819996manual(m5)f1826pcompact
7audia43.120086auto(av)f1827pcompact
8audia4 quattro1.819994manual(m5)41826pcompact
9audia4 quattro1.819994auto(l5)41625pcompact
10audia4 quattro220084manual(m6)42028pcompact
11audia4 quattro220084auto(s6)41927pcompact
12audia4 quattro2.819996auto(l5)41525pcompact


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

Answer & Explanation Solved by verified expert
4.0 Ratings (642 Votes)

*****
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()


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students