 # Python Programming Practice

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import random

def run_simulation(annual_spend, inflation_rate, savings_balance, interest_rate, num_years, inflation_change, interest_change):
# Store savings in list
savings = []
# For each year:
for year in range(num_years):
# Update the annual spend by inflation rate
annual_spend *= (1 + inflation_rate)
# Reduce the savings balance by the annual spend
savings_balance -= annual_spend
# Update the savings balance by interest rate
savings_balance *= (1 + interest_rate)
# Add savings balance to savings in list
savings.append(savings_balance)
# Update inflation rate
inflation_rate = modify_rate(inflation_rate, inflation_change)
# Update interest rate
interest_rate = modify_rate(interest_rate, interest_change)
# Return savings in list
return savings

def modify_rate(rate, change):
"""
Calcualate a random value within the change of given rate

Arguments:
rate -- The intial rate to change from
change -- The maximum amount to change of the given rate

Returns a random value within change of the given rate

Explation:
random.random() calculates a random value between o and 1.
Thus random.randm()*2 gives a value between 0 and 2,
so 1 - random.random()*2 gives a value between -1 and 1.
Multiplying by change gives a value between -change and change, which is then added to the rate.
"""

return rate + change * (1 - random.random() * 2)

def main():

# Last year expense
while True:
try:
annual_spend = int(input("How much did you spend last year to support your current life style? "))
if annual_spend >= 0:
break
else:
except ValueError:
print( "Please enter a non-negative integer")

# Inflation rate
while True:
try:...
\$45.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.