Python

a=raw_input(“Enter a number”)
def distance_from_zero(a):

if type(a)==int or type(a)==float:
print (abs(a))
else:
print “Nope”

distance_from_zero(a)

Why is this program always giving output as nope inspite of entering an integer as an input?

So type a isn’t a integer or a float, what is it then? might be a good thing to check

i will give you a hint:

https://docs.python.org/2/library/functions.html#raw_input

specifically this bit: The function then reads a line from input, converts it to a string (stripping a trailing newline),

1 Like