2

Would anyone please help me find out why I get an indentation error in line 3

def calc(f1,f2,f3):
remove_list = ['01ST', '02ND', '03RD', '04TH', '05TH', '06TH', '07TH', '08TH', '09TH']
    if f2 in remove_list:
        f2 = f2.replace('0','')
    else:
        f2 = f2
f1 = f1.strip()
f2 = f2.strip()
f3 = f3.strip()     
f1 = str(f1).replace('.0','')
x = f1+' '+f2+' '+f3
return x

THe function is simply supposed to evaluate the if statement then concatenate fields f1, f2 and f3. Do I need to end the if statement somehow?

  • why do you need to set f2=f2? This seems redundant. Just remove the else statement. – Fezter Sep 1 '15 at 3:13
5
  1. You need to indent the function you're defining.
  2. Don't further an indent for an if statement until after the if statement.

    def calc(f1,f2,f3):

        remove_list = ['01ST', '02ND', '03RD', '04TH', '05TH', '06TH', '07TH', '08TH', '09TH']
        if f2 in remove_list:
            f2 = f2.replace('0','')
        else:
            f2 = f2
        ...
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.