Python Lesson: Functions (19/19)


#1

def distance_from_zero(h):
if type(h) == int or type(h) == float:
return abs(h)
else:
return “Nope”

It gives me the error “Your function seems to fail on input True when it returned ‘1’ instead of ‘Nope’”


#2

Hi @hsn20,

Since your posted code is not formatted, we cannot check its indentation. Make sure that your original code is properly indented in the editor window. Then, just in case you mistakenly redefined a built-in function, such as type, in a previous submission, refresh the page and submit the code again.

See How do I format code in my posts?.


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

#4

This line should be indented by a total of four spaces so that it is within the if block …

  return abs(h)

This else header should be indented by a total of only two spaces, so that it matches alignment with the if header …

    else:

Make certain that you use only spaces for the indentations rather than using any tabs here. Never use a combination of spaces and tabs for indentation within a Python program. Choose one or the other.


#5

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