Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

Can someone tell me what is wrong with this code? It is Codecademy review of functions. The error states that it is not returning an absolute value for integers, and I presume floats too.... def distance_from_zero(x): first = type(x) if first == "int": return abs(x) elif first == "float": return abs(x) else: return "This isn't an integer or a float!"

OpenStudy (anonymous):

when you put "if first == "int": you're comparing with a string: 'int', for type just use: if fist == int: you would see the int in purple I think

OpenStudy (anonymous):

Thanks, that did it. I really appreciate waking up to an answer!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!