Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request, shelve
- url = 'http://nancymcohen.com/csci133/cpiai.txt'
- file = urllib.request.urlopen(url)
- lines = file.readlines()
- file.close()
- cpi = {}
- for line in lines:
- items = line.decode().split()
- if len(items) > 0 and items[0].isdigit():
- cpi[int(items[0])] = [float(item) for item in items[:13]]
- shelf = shelve.open('cpi')
- shelf['cpi'] = cpi
- shelf.close()
- data = input('enter query: ')
- data = data.split(" ")
- data = [int(i) for i in data]
- year = data[0]
- def Average(lst):
- return sum(lst) / len(lst)
- print(cpi[year][1:13], Average(cpi[year][1:13]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement