#Future Value #It is difficult to make a budget that spans several years, #because prices are not stable. If your company needs 200 pencils #per year, you cannot simply use this year's price as the cost of #pencils two years from now. Because of inflation the cost is likely #to be higher than it is today. # #Write a program to gauge the expected cost of an item in a specified #number of years. The program asks for the cost of the item, #the number of years from now that the item will be purchased, # and the rate of inflation. The program then outputs the estimated #cost of the item after the specified period. #Have the user enter the inflation rate as a percentage, like 5.6 (%). #Your program should then convert the percent to a fraction, like 0.056, #and should use a loop to estimate the price adjusted for inflation. from graphics import * def main(): print "This program calculates the expected price of an item" price = input("Please, input the today's price of an item: ") years = input("Please, input the number of years from now that the item will be purchased: ") inflation = input("Please, input the inflation rate: ") print "Now let's do it in graphics!" window=GraphWin('Predicting item\'s price.',320,240) window.setBackground("white") # let's draw the scale (you may skip this part till # drawing bars: starting_price=price inflation = inflation/100.0 for i in range(years): price=price+price*inflation print "price=%f" %(price) print "start price=%f, price=%f" %(starting_price,price) diff=price-starting_price scale=diff/4. print "difference=%f, scale=%f" %(diff,scale) l1=str(starting_price) l1=l1[:4] print "label 1=%s" %(l1) label2=starting_price+scale l2=str(label2) l2=l2[:4] print "label 2=%s" %(l2) label3=starting_price+2*scale l3=str(label3) l3=l3[:4] print "label 3=%s" %(l3) label4=starting_price+3*scale l4=str(label4) l4=l4[:4] print "label 4=%s" %(l4) label5=starting_price+4*scale l5=str(label5) l5=l5[:4] print "label 5=%s" %(l5) Text(Point(20,30), l5).draw(window) Text(Point(20,80), l4).draw(window) Text(Point(20,130),l3).draw(window) Text(Point(20,180),l2).draw(window) Text(Point(20,230),l1).draw(window) # draw bars for successive years price=starting_price # I saved the initial price of the item # aside, and now I'm updating the price value to initial one # need variable pixels to find the bar height pixels=(50.)/scale print "pixels=%f" % (pixels) #inflation = inflation/100.0 for i in range(years): price=price+price*inflation print "price=%f" % (price) # draw bar for this value x=i * 25 + 60 height=(price-starting_price)*pixels print "height=%f" % (height) bar=Rectangle(Point(x,230),Point(x+25,230-height)) # bar=Rectangle(Point(x,230),Point(x+25,30)) bar.setFill('green') bar.setWidth(2) bar.draw(window) print "In ", years, "years the price of the item will be ", price print "Have a good day!" flag=raw_input("Please input any symbol to close the window:") window.close() main()