I just don't know what's wrong


#1



Please help me. I just don't know what's wrong. Can someone show me what the new code is supposed to look like? Thank you.


I type in -6 because it asks for user input and then it always gives me this:

Traceback (most recent call last):
File "python", line 7, in
TypeError: not enough arguments for format string


The program is supposed to respond something like "You put in -6 and the absolute value is 6" but instead it gives me an error message


def distance_from_zero(a):
    if type(a) == float or type(a) == int:
        return abs(a)
    else:
        return "Nope"
h = raw_input()
print "You put in %s and the absolute value is %s" % h % distance_from_zero(h)


#2

Try this

def distance_from_zero(a):
    if type(a) == float or type(a) == int:
        return abs(a)
    else:
        return "Try again"
h = raw_input()
x = distance_from_zero(h)
print "You put in %s and the absolute value is %s" % (h,x)

I was trying it with pythonfiddle, but because the "type()" function doesn't work there for some reason, the answer always comes out with "Try again"


#3

I'm having the same issue


#4

Hi flamingdinosaurjizp,

This is my code:
def distance_from_zero(number):
if type(number) == int or type(number) == float:
return abs(number)
else:
return "Nope"

It checks if the argument is an int or float and either returns the absolute value or nope.
Hope this helps!


#5

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