Issue with a function


#1

having some issues when I run this is my idle python 2.7

def distance_from_zero(num):
if type(num)==int() or type(num)==float():
#this should only take int()or float()
print abs(num)
#this line should give the absolute value
else:
print “nope”
#this is not working properly it
#is printing the num given not the
#absolute of the num given and not printing nope either


#3

Better if you post a complete example that can be executed without any interaction or modification because that’s plenty of opportunity to do it differently from you.
And, it needs to be an exact copy, what you have there isn’t valid syntax, it needs to be possible to copy from your post and get the same thing to happen


#4

def distance_from_zero(num):
if type(num)==int() or type(num)==float():
#this should only take int()or float()
print abs(num)
#this line should give the absolute value
else:
print “nope”
#this is not working properly it
#is printing the num given not the
#absolute of the num given and not printing nope either


#5

apparently when I pasted this in the area was correct in space and indention but when it posted all the indentions went away.

def ditsance_from_zero(num:)
if type(num)==int() or type(num)==float():
print abs(num)
else:
print “nope”
didn’t work again


#6

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