-1

I want the code to increase my semi_annual_income every six months, by making the the semi_annual income increase every six months with by specific percentage. so it was suppose to be according to my math 1000(1.2)^i/6 this equation would increase my income by 0.2 every 6 months where the i is divisible by 6.

I tried to both the expressions when I use the expression 1000(1.2)^i/6 it will give me a very huge number. and the expression 1000(1 +0.2) is giving me the exact answer that 1000(1 + 0.2) should have given me.

number_of_months = 0
total_cost = 100000
semi_annual_income = 1000
starting_salary = 10
semi_annual_rise = 0.2
while semi_annual_income < total_cost:
    for i in range(100):
        if float(i)%6 == 0:
            power_number = float(i)/6
            # i am using this to make it increase the semi_annual income just only every six months
            semi_annual_income = semi_annual_income *(float(1) + float(semi_annual_rise))
            print(power_number)
            print(semi_annual_income)
            #semi_annual_income = (semi_annual_income *(float(1) +  float(semi_annual_rise))** float(power_number))
            #The above written code is giving me a very huge number i  want it to give me the answer as 1000(1 + 0.2)^i/6
    break

I got the answer I wanted from the code but I don't understand why is it giving me the answer without the power and the one with the power is not giving me the answer.

Blckknght
  • 100,903
  • 11
  • 120
  • 169
J jezani
  • 1
  • 1

1 Answers1

0
number_of_months = 0
total_cost = 100000
semi_annual_income = 1000
starting_salary = 1000
semi_annual_rise = 0.2
number_of_months = 0
while semi_annual_income < total_cost:
    for i in range(1,100):
        if float(i)%6 == 0:
            power_number = float(i)/6# i am using this to make it increase the 
semi_annual income just only every six months
            number_of_months = number_of_months + 1
            semi_annual_income = starting_salary *(float(1) + 
float(semi_annual_rise))**(power_number)
            print(power_number)
            print(semi_annual_income)
            print(number_of_months)
# I think my mistake was the i used semi_annual-income instead of starting salary, this code works as i wanted it to be.
    break
J jezani
  • 1
  • 1