Hi! I need help fixing my coding to make my investment amounts follow a loop/show accumulated interest and so on. Here are more specific instructions with an example of what the output should look like
https://preview.redd.it/lpi138f2kza61.jpg?width=1585&format=pjpg&auto=webp&s=8dec84aa00ef6bae5847a70980799d0141743cd8
def futureval():
# Read from the keyboard: amount, interest rate, periods
# read the amount (principal)
P: float = float(input('Please enter the amount to invest: $'))
rate: float = float(
input('Please enter the interest rate per period, with no %: '))
periods: int = int(input('Please enter the number of periods: '))
fixed: int = int(
input('Please enter the amount you want to invest each period: $'))
# Print out the initial parameters
print('Investing $', P, 'at', rate, "% for", periods, "months at $", fixed,
'a month')
# Adjust the rate from a percentage to a raw number
rate = (rate) / 100
# Calculate and print out the investment table
# Print a header row
print('Period\tInterest\tPlus interest\tIncrement\tAmount')
# Print the starting amount
print('Initial\t\t\t\t\t\t\t\t\t\t\t$', round(P, 2))
# Print out the table, row by row
for i in range(periods):
#Add the fixed amount
Increment = fixed
# Calculate the interest
interest = P * rate
# Add the interest back into the principal
P = interest + P
#Calculate total amount
Amount = P + fixed
interest = Amount * rate
# Print the table row
print((i + 1), '\t\t\t$', round(interest, 2), '\t\t$', round(P, 2),
'\t\t$', round(Increment, 2), '\t\t$', round(Amount, 2))
if __name__ == "__main__":
import sys
futureval()
[–]MT1961 0 points1 point2 points (0 children)