Created
May 1, 2017 23:35
-
-
Save ebovio/ad43e2fa57e237adeee8e010c48cc707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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