This forum is now read-only. Please use our new forums! Go to forums
Can anyone help me figure out wats wrong?
Can anyone help me figure out wats wrong with my code? I keep getting the error:”Your function seems to fail on input -10 when it returned ‘Nope’ instead of ‘10’”
def distance_from_zero(p): p=raw_input(“Enter the number”) if type(p) == int or type(p)==float: print abs(p) else: return “Nope” return distance_from_zero(p)
Answer 54a59d88937676b1c4001903
There is no indentation error.. I already checked on that!
Answer 54a5dd0b51b887f490001d8c
When you post code, always format it by selecting the code, and then clicking the {}
button above the editing area, so that we can see important details, such as the indentation and underscores.
This function should not perform input and output, therefore it should include no raw_input
or print
statements. So, move the following to outside the function …
p=raw_input("Enter the number")
After that, you can do this …
print distance_from_zero(p)
Inside the function, you have …
print abs(p)
Instead of print
ing results, the function should return
results, which will be output by the print
statement suggested previously. So revise your statement to be ..
return abs(p)
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency