Functions question


File "python", line 6
SyntaxError: 'return' outside function

I am not sure why this code isn't running. Can someone help please?


import math

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



What are you trying to do with return type(n)?


I'm not sure what it should be returning?


Your function does nothing, if it returns type(n) at the beginning. Function ends always to the return- statement, and in your case it is at the beginning so the function ravels up.


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