"Review: Built-In Functions"


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/4/3?curriculum_id=4f89dab3d788890003000096


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


#2

please take another good look at the indent of your coding, for example if you have a function, what is inside the function should be indented:

def test_function():
   print "i am inside the function"
print "i am not"

take a look at the indent of your whole code


#3

[quote="dio123, post:1, topic:40222"]
def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"

 I indented all of my code, but it still doesn't run correctly.  Please advise.

Thanks!

Ian Michael Jones


#4

What error are you getting when you click save & submit?


#5

The coding error that comes up after I run my code states,

"Oops, try again. 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."

Please advise.

Thanks!


#6

please post your code using markup:

So we can have a proper look at your code and indent


#7

Here is my code for your review. I still get the same error even after using backticks (') before and after 'distance_from_zero.' Please advise.

Thanks!

Ian Michael Jones


#8

Here is my code:

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

Thanks!


#9

okay, but you should also indent after a if statement:

if type(n) == int or type(n) == float:
   return abs(n)

and your else should also be indented so that it is inside the function. Indent has been important from the beginning, please take a second to realize how it works (read something about it, if that helps)


#10

I indented every line of my code and it still doesn'rt run correctly. Here is my code:

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

Please advise.

Thanks!


#11

*doesn't run correctly.


#12

Dude, after the if and else there should be additional indents. Please learn how to indent your code


#13

I did indent every line of my code; however, my code still doesn't run correctly. My code obviously didn't indent properly after I "Cut" and "Pasted" it. Here is my code.:

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

#15

It appears that my code didn't indent properly yet again. Here is a hyperlink to the coding exercise that i am working on called "Review: Built-In Functions" under the "Functions" heading.: https://www.codecademy.com/courses/python-beginner-c7VZg/4/3?curriculum_id=4f89dab3d788890003000096.


#16

*I am working on called...


#17

what @stetim94 was trying to explain to you was that there should be yet another indent after your if and else statements like so:

def my_function():
----if #this:
--------#do this
----else:
--------#do this

# knowtice the amount of indent, shown using -'s

#18

Looking at your code:

def 'distance_from_zero(n)':                # remove apostrophes
      if type(n) == int or type(n) == float:
      return abs(n)                         # line to indent further
      else:
      return "Nope"                         # line to indent further

Check that each indentation is exactly four spaces, no more, no less.


#19

My code runs correctly now. Thanks for all of your help mtf. I really do appreciate it. Take care!