简体   繁体   中英

I have an unindentation error that I can't figure out how to fix

I am currently doing an assignment for the MIT introduction to python , part C. I keep on getting:

IndentationError: unindent does not match any outer indentation level  

Here is the code:

#MIT C
# setting up varaibles
interest = float(0.04)
semi_annual_raise = float(0.07)
total_cost=1000000
portion_down_payment=0.25
downpayment=total_cost*portion_down_payment
starting_annual_salary=float(input("Enter the starting salary: "))
monthly_salary=starting_annual_salary/12
current_savings = 0
# setting up guess
programe = 1 
low=0
high = 1
step = 0
month = 1
guess = (high+low)/2.0
tolerance=500
savings = 0
# semi annual raise code
while programe == 1:
        end_salary = (monthly_salary * 36) * (interest * 3)
        current_savings = guess * end_salary
        savings = guess * end_salary
        if current_savings >  downpayment +- tolerance:
             print("the savings rate was too high ," , guess)
             print("reunning program")
             low = guess
             guess = (high + low) / 2.0
             current_savings = guess * end_salary
             savings = guess * end_salary
        elif current_savings < downpayment +- tolerance:
             print("the savings rate was too low ," , guess)
             print("rerunning program")
             high = guess
             guess = (high+low)/2.0
             current_savings = guess * end_salary
             savings = guess * end_salary
         else savings == downpayment +- tolerance:
             print("enter starting salary: " , starting_annual_salary)
             print("best savings rate:" , guess)
             print("steps in bisection search" , step)
             programe = 0.5
        continue
    if programe == 0.5:
        break all

I modified the code a bit so it will run without error messages:

#MIT C
# setting up varaibles
interest = float(0.04)
semi_annual_raise = float(0.07)
total_cost=1000000
portion_down_payment=0.25
downpayment=total_cost*portion_down_payment
starting_annual_salary=float(input("Enter the starting salary: "))
monthly_salary=starting_annual_salary/12
current_savings = 0
# setting up guess
programe = 1 
low=0
high = 1
step = 0
month = 1
guess = (high+low)/2.0
tolerance=500
savings = 0
# semi annual raise code
while programe == 1:
    end_salary = (monthly_salary * 36) * (interest * 3)
    current_savings = guess * end_salary
    savings = guess * end_salary
    if current_savings >  downpayment +- tolerance:
        print("the savings rate was too high ," , guess)
        print("reunning program")
        low = guess
        guess = (high + low) / 2.0
        current_savings = guess * end_salary
        savings = guess * end_salary
    elif current_savings < downpayment +- tolerance:
        print("the savings rate was too low ," , guess)
        print("rerunning program")
        high = guess
        guess = (high+low)/2.0
        current_savings = guess * end_salary
        savings = guess * end_salary
    elif savings == downpayment +- tolerance:
        print("enter starting salary: " , starting_annual_salary)
        print("best savings rate:" , guess)
        print("steps in bisection search" , step)
        programe = 0.5
    continue
    if programe == 0.5:
        break

However, I think it is stuck in an ongoing loop. I am not sure what exactly you want the program to do, so I could not fix it.

It looks like everything from the start of end_salary to the continue statement has been indented with 8 spaces, instead of 4.

It also looks like all of the lines under each if statement are indented with 5 spaces instead of 4.

Try pulling those back and you should see the error go away.

Here's my sanitized code:

#MIT C
# setting up varaibles
interest = float(0.04)
semi_annual_raise = float(0.07)
total_cost=1000000
portion_down_payment=0.25
downpayment=total_cost*portion_down_payment
starting_annual_salary=float(input("Enter the starting salary: "))
monthly_salary=starting_annual_salary/12
current_savings = 0
# setting up guess
programe = 1 
low=0
high = 1
step = 0
month = 1
guess = (high+low)/2.0
tolerance=500
savings = 0
# semi annual raise code
while programe == 1:
    end_salary = (monthly_salary * 36) * (interest * 3)
    current_savings = guess * end_salary
    savings = guess * end_salary
    if current_savings >  downpayment +- tolerance:
        print("the savings rate was too high ," , guess)
        print("reunning program")
        low = guess
        guess = (high + low) / 2.0
        current_savings = guess * end_salary
        savings = guess * end_salary
    elif current_savings < downpayment +- tolerance:
        print("the savings rate was too low ," , guess)
        print("rerunning program")
        high = guess
        guess = (high+low)/2.0
        current_savings = guess * end_salary
        savings = guess * end_salary
    else savings == downpayment +- tolerance:
        print("enter starting salary: " , starting_annual_salary)
        print("best savings rate:" , guess)
        print("steps in bisection search" , step)
        programe = 0.5
    continue
    if programe == 0.5:
        break all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM