Skip to content

Instantly share code, notes, and snippets.

@ebovio
Created May 1, 2017 23:35
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 ebovio/ad43e2fa57e237adeee8e010c48cc707 to your computer and use it in GitHub Desktop.
Save ebovio/ad43e2fa57e237adeee8e010c48cc707 to your computer and use it in GitHub Desktop.
import urllib.request
def average(lst1, index):
funclst = []
for car in lst2:
templst = car.split()
funclst.append(templst[index])
funclst = list(map(float,funclst))
av = sum(funclst)/len(funclst)
return av
def main():
url = 'https://ww2.amstat.org/publications/jse/datasets/93cars.dat.txt'
response = urllib.request.urlopen(url)
data = response.read()
txt = data.decode('utf-8')
lst = txt.split()
lst2 = []
i,j = (0,0)
while i < len(lst):
if i%26 == 0:
lst2.append(lst[i])
j += 1
else:
lst2[j-1] += "" + lst[i]
i += 1
print("The average gas mileage in city is:", average(lst2,6))
print("The average gas mileage in highwat is:", average(lst2,7))
print("The average midrange price of the vehicles in the set:", average(lst2,4))
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment