Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python multiply your last answer by a constant

Tags:

python

so I'm trying to display salary with annual % increase for certain amount of years

print('Enter the strting salary: ', end ='')
SALARY = float(input())
print('Enter the annual % increase: ', end ='')
ANNUAL_INCREASE = float(input())

calculation1 = ANNUAL_INCREASE / 100
calculation2 = calculation1 * SALARY
calculation3 = calculation2 + SALARY



Yearloops = int(input('Enter number of years: '))

for x in range(Yearloops):
    print(x + 1, calculation3 )

This is my output so far by entering 25000 as salary, 3 as % increase and 5 for years.

1 25750.0
2 25750.0
3 25750.0
4 25750.0
5 25750.0

I need to multiply the last answer again by the % increase. Should be like this

1 25000.00 
2 25750.00 
3 26522.50
4 27318.17 
5 28137.72

Can someone show me how to do it? Thanks.

like image 297
Nanor Avatar asked Nov 27 '25 03:11

Nanor


1 Answers

You need to put your calculations inside your for loop so that it occurs every year instead of just once

salary = float(input('enter starting salary: '))
annual_increase = float(input('enter the annual % increase: '))
years = int(input('enter number of years: '))

for x in range(years):
    print(x + 1, salary)

    increase = (annual_increase/100) * salary
    salary += increase

Entering 25000, 3%, and 5 years outputs

1 25000.0
2 25750.0
3 26522.5
4 27318.175
5 28137.72025
like image 66
nj1234 Avatar answered Nov 29 '25 18:11

nj1234