Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Read from a file that you make the current price of an item and its price...

1 answer below »
Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Read from a file that you make the current price of an item and its price one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year from the price of the item one year ago and then divide the results by the price a year ago. Your program must contact a function to get the input, a function to calculate the results, and a function to output the results. Use appropriate parameters to pass the information in and out of the function. Do not use any global variables.
Answered 1 days AfterJul 26, 2021

Answer To: Write a program that outputs inflation rates for two successive years and whether the inflation is...

Pratap answered on Jul 28 2021
161 Votes
"""
Program to calculate and display Inflation rates
"""
# import library
import datetime
# creat
e a class for items
class Item:
# create constructor for the class
def __init__(self, name, year, price):
self.name = name
self.year = year
self.price = price
def __str__(self):
return str(self.name) + "\t" + str(self.year) + "\t" + str(self.price)
def calculate_inflation(year, price):
"""
Function to calculate inflation rates
:param year: list of years
:param price: list of prices
:return: list of inflation rates
"""
result = []
for index in range(len(year)):
try:
year_max = year.index(max(year_list))
year_min = year.index(min(year_list))
if (len(year) == 3) and (index != year_max) and (index != year_min):
inflat1 = (price[index] - price[year_max]) / price[index]
inflat2 = (price[year_min] - price[index]) / price[year_min]
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here