Can someone help me with this?


#1



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


It says I have a NameError, and that maybe I forgot to create a function called distance_from_zero

Though I am confused because I expected that my code would be correct because I did define desitance_from_zero, as you can see


import math
def distance_from_zero(num):

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


#2

Indentation is vitally important in Python since that is how the interpreter defines scope. The size of the indent is not critical, so long as it is consistent in any one block.

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

distance_from_zero(5)

As far as I know, abs() is part of the core, so we don't require the math module.


#3

Thank you, it finally worked!


#4

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