SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib.request, shelve
  2.  
  3. url= 'http://nancymcohen.com/csci133/cpiai.txt'
  4. file = urllib.request.urlopen(url)
  5. lines = file.readlines()
  6. file.close()
  7.  
  8. cpi = {}
  9. for line in lines:
  10.     items = line.decode().split()
  11.     if len(items)>0 and items[0].isdigit():
  12.         cpi[int(items[0])]=[float(item) for item in items[:13]]
  13.  
  14. shelf = shelve.open('cpi')
  15. shelf['cpi']= cpi
  16. shelf.close()
  17.  
  18. def pctIncrease(begin, end):
  19.     return100*(end/begin-1)
  20.  
  21. print('    Percent increase in CPI')
  22. print('       (Jan - Jan)')
  23. print('    1 year 5 years 10 years')
  24.  
  25. pattern1 = '{0:d}{1:6.1f}'
  26. pattern2 = '{0:9.1f}'
  27.  
  28. for year in range(1914, 2009):
  29.     currentCPI = cpi[year][1]
  30.     pct = pctIncrease(cpi[year-1][1], currentCPI)
  31.     print(pattern1.format(year,pct), end='')
  32.     if year-5>= 1913:
  33.         pct= pctIncrease(cpi[year-5][1], currentCPI)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top