If -else


#1

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

the error message says
Have you defined the function distance_from_zero(n)?
But I have done that haven't I?


#2

Why is the else statement indented into the if statement? You also have extra whitespace in the return "Nope" block.


#3

Thanks! It worked out well after your corrections.

Kristian Strid
Lektor i fysik


#4

Great! I'm glad it worked.

Happy Coding,
Harrypotter91


#5

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