Python lesson 19/19 question

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

Error messages:
File “python”, line 4
SyntaxError: invalid syntax

It looks like you have a NameError. Maybe you forgot to create a function called distance_from_zero? Check the error message for more info! - global name ‘distance_from_zero’ is not defined


Is that all of your code?

I ran the code you posted in Python and I don’t get an error - either in the Codecademy editor, or on Python on my computer…


Thanks, that’s all of it. It’s like the Solution except it doesn’t work when I hit Run. I copied and pasted the Solution to get to Next. Now, I’ll move on.


That’s very weird, but if your code was identical to the solution it’s possible you just ran into a glitch with the editor. I’ve had the odd exercise on Codecademy where it wouldn’t accept a valid solution no matter how many times I tried.

Typically leaving and reloading the exercise straightens it out, but I’m glad you’ve managed to get to the next exercise. :slight_smile:

Let us know if you need any more help with the Python course. :slight_smile:


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