Oct-02-2017, 04:27 PM
Hi, I am just beginning to learn python, this was an exercise I got from a resource online and tried to solve.
The code below is supposed to take an argument, check whether it is an integer or float in which case it should return the absolute value of the number, otherwise it returns a "Nope" string.
When I run the code below, I just get a "Nope" even when i input an integer or a float. I use the atom text editor and run it from windows powershell...
num = raw_input('Enter a number: ')
def distance_from_zero(num):
if type(num) == int or type(num) == float:
print abs(num)
else:
print 'Nope'
distance_from_zero(num)
The code below is supposed to take an argument, check whether it is an integer or float in which case it should return the absolute value of the number, otherwise it returns a "Nope" string.
When I run the code below, I just get a "Nope" even when i input an integer or a float. I use the atom text editor and run it from windows powershell...
num = raw_input('Enter a number: ')
def distance_from_zero(num):
if type(num) == int or type(num) == float:
print abs(num)
else:
print 'Nope'
distance_from_zero(num)