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

In Lecture 4...I understand that he is defining a function with 3 arguments. I'm not understanding the body of the code from """x,y,epsilon floats. epsilon >0.0... can some really explain this for me. I'm so confused that I'm not even sure how to ask Google.

OpenStudy (anonymous):

The function's purpose is to determine if x is within epsilon of y. So, the text in triple quotes at the beginning of the function explains that x and y are expected to be integers or floats and that epsilon is expected to be greater than 0. The function makes no sense if these specifications aren't met. The only line of code to worry about is the return expression. This expression will return true or false. A good way to understand it is to use some example values. So, if x=2, y=3 and epsilon =1, I am asking the function to tell me if 2 is within 1 of 3. The expression on the line with the return statement does this by subtracting y from x, or 2 from 3 in our example, and seeing if the value is less than or equal to epsilon, or 1 in our example. Our value will be 1 (3-2=1) and so is equal to epsilon. The function will then return true. I hope that this helps.

OpenStudy (anonymous):

the text between the triple quotes is a docstring. it is there to explain how to use the function and can include the result of running the function in the shell.. you should get in the habit of writing docstrings for your functions and classes - it makes it easier for people to understand what the function is doing and it helps you remember what it is doing when you go back to look at it six months from now.

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!