Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Created May 7, 2015 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilrg18/f085b4311a9a1fe6c75d to your computer and use it in GitHub Desktop.
Save gilrg18/f085b4311a9a1fe6c75d to your computer and use it in GitHub Desktop.
Cars
def car():
x=open("93cars.dat.txt","r")
mpgc=0
mpgh=0
mp=0
cars=0
f=1
for line in x:
if f%2==1:
mpgc=mpgc+float(line[52:54])
#print ("mpgc",mpgc)
mpgh=mpgh+float(line[55:57])
#print ("mpgh",mpgh)
mp=mp+float(line[43:46])
#print ("mp",mp)
cars=cars+1
#print ("cars",cars)
f=f+1
#print ("f",f)
i=round(mpgc/cars,2)
j=round(mpgh/cars,2)
k=round(mp/cars,2)
return (i,j,k)
s=car()
print ("CityMPG",s[0] ,"HighwayMPG",s[1] , "AverageMidrangePrice",s[2])
#GILBERTO ROGEL GARCÍA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment