Again stuck on 19/19, dont know where I messed up


#1

My code is as follows:

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

I checked my indentations and re wrote all the code from scratch, and it’s giving me the following error:

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

Python says:

File “python”, line 2
if type(x) == int or type(x) == float
^
SyntaxError: invalid syntax


#2

If your code crashes/doesn’t run at all then you should pay no attention at all to what codecademy says and address the crash first

Also note that when posting code you need to inform the forum that it should not apply normal formatting rules to it, or you end up posting something very different from what you’re actually running

Syntax errors are generally trivial to identify and fix. Look up examples for the things you’re doing in your code. You can quickly narrow down the issue by removing everything else until you only have a function definition with no content or just an if-statement or just an expression etc. So long as you remove almost everything you won’t have to compare a whole lot. It does take a careful eye though. (removing stuff is of course pretty crude, but it’s simple)


#3

Looks like I forgot a colon after my if statement. Thanks.


#4

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