Review Built-In functions - looks correct as per previous Q&A posts


#1

Topic 19. Review: Built-In functions.

I have read a number of posts on the Q&A to try to solve my failings but am not getting there. As far as i can tell my code is correct.
I get a syntax error referring to line 4; where "else:" is termed. And a NameError regarding distance_from_zero having not being defined indicating that I may have forgotten to create a function for it.

Thanks! G

'''def distance_from_zero(number):
    if type(number) == int or type(number) == float:
        return abs(number)
        else:
            return "Nope"''''

#2

First of all remove the three single quotes in the begginning and ending of your code and just make sure your else statement is on the same indentation level as your if statement,

def example():
    if condition:
        some code
    else:
         some code

#3

I did those to transfer the code as we suggested in the formatting part before i posted. They aren't there otherwise.


#4

Ok i did that, having done the indentation like that before, and it worked. sigh


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.