Warning: The in-code checker for homework 5 can make mistakes

 3 1 The checker can evaluate your answer to True if it has nan (not a number). Always print your answer to make sure you got it right. In my case, I got this (I know most people won't make the mistake I did, but better to be safe): First Test case  Test case correct! [0.000, 0.000] -> [0.000, 0.000] [1.000, 0.000] -> [nan, nan] [2.000, 0.000] -> [nan, nan] [3.000, 0.000] -> [nan, nan] [4.000, 0.000] -> [nan, nan] [5.000, 0.000] -> [nan, nan] [6.000, 0.000] -> [6.000, 0.000] [6.000, 1.000] -> [nan, nan] [6.000, 2.000] -> [nan, nan] [6.000, 3.000] -> [6.000, 3.000] [5.000, 3.000] -> [nan, nan] [4.000, 3.000] -> [nan, nan] [3.000, 3.000] -> [nan, nan] [2.000, 3.000] -> [nan, nan] [1.000, 3.000] -> [nan, nan] [0.000, 3.000] -> [0.000, 3.000] [0.000, 2.000] -> [nan, nan] [0.000, 1.000] -> [nan, nan]  Second Test case Test case correct! [0.000, 0.000] -> [0.000, 0.000] [1.000, 0.000] -> [nan, nan] [2.000, 0.000] -> [4.000, 0.000] [3.000, 0.000] -> [nan, nan] [4.000, 0.000] -> [4.000, 4.000] [5.000, 0.000] -> [nan, nan] [6.000, 0.000] -> [0.000, 4.000] [6.000, 1.000] -> [nan, nan]  asked 20 Mar '12, 12:02 yoshi 4.0k●8●26●59 accept rate: 33%

 1 You may want to add math.isinf(x) and math.isnan(x) checks to the close_enough(...) routine. There is a small change to the test routine that will catch NaN input. Inf input would already be handled correctly. The original routine is: def close_enough(user_answer, true_answer, epsilon = 0.03): if abs(user_answer - true_answer) > epsilon: return False return True  Since (nan < x) is always false, as is (nan > x) and (nan == x), then switching the logic around will catch NaNs. def close_enough(user_answer, true_answer, epsilon = 0.03): if abs(user_answer - true_answer) < epsilon: return True return False  Or just, def close_enough(user_answer, true_answer, epsilon = 0.03): return abs(user_answer - true_answer) < epsilon  answered 20 Mar '12, 12:43 EricHui-2 799●2●7●25
 0 If your output is blowing up like mine did, you should take a look at this post answered 20 Mar '12, 13:51 yoshi 4.0k●8●26●59
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×5,185
×69
×3
×1
×1