# Unit 4-8 first searh question passes all the test cases in the video but still fails on submit

 9 1 Hi all, I tried to submit my answer to the first search question. I tested it in all the cases in mentioned in the video and it returns expected results. However, when I tried to submit it, it failed. Does anyone know what test case I should try? asked 12 Mar '12, 17:14 leo chan-4 299●2●3●10 accept rate: 0% And I tried Sebastian's code from the answer. It also failed with the same error. Following some peoples' comments, I modified Sebastian's code to return either the solution or the word fail. It worked when I hit run but still gave the error. (14 Mar '12, 13:11) Alex Brown-1

 6 My answer got rejected first time as well. Make sure you do this: Have the function return it's values, rather than print. Do not output anything else Call search() at the end of your script. Hope this helps! answered 12 Mar '12, 18:37 Tom Rijndorp-1 642●1●3●14 This worked for me also!! If your program is accepted "Correct!" is displayed above the program output window. (12 Mar '12, 19:32) david radnell This worked for me. To be safe I also printed "fail", I'm not sure if it would have worked without it. (12 Mar '12, 19:45) josephks Most importantly, you must return the word 'fail' in the failure case rather than just printing it as instructed. (13 Mar '12, 00:03) Pax
 2 Sorry @leo -- close but not quite right. Here is the same reason when code is pasted in the code editor window for 4.8,4.9 and 4.12 - if the 'hidden last line' in the window is somehow deleted- then the submission fails or there are spurious error messages when in fact the function submitted could be correct Solution: everything works now. For questions > 4.8 Reset them, and then paste in only the relevant functions. answered 13 Mar '12, 01:14 RoboCar2012 147●3●10 Thanks. After spending way too long trying to get it to work, the copy and reset trick worked. (13 Mar '12, 21:53) Gregory Osch... Yeah! that trick worked fine. Thanks (14 Mar '12, 08:48) escriva What if you also define some other functions? (14 Mar '12, 12:46) Anne Paulson That is the solution I found as well. However, it seems to have nothing to do with a "hidden last line". It's just some bug in the web site they need to track down and fix. I've added this thread about it: http://www.udacity-forums.com/cs373/questions/21451/workaround-for-incorrect-you-may-have-incorrectly-defined-a-function-bug I would guess it is more likely a problem with file formatting like CR LF vs LF at the end of lines or with the last line in the file not having a trailing LF that is causing problems. It's totally separate from the bug in some browsers not showing the last line of the code window (as far as I can tell). (16 Mar '12, 01:23) Curt Welch
 1 I defined some (unneeded) global variables that i wasn't reinitializing. It's possible they're calling our function on multiple different setups. Once i moved those variables into my function i was marked as being correct. answered 13 Mar '12, 00:10 srparish 104●3●6 I believe this is the true solution. It seems that the "grader" calls your search function multiple times with the grid set to different values in each. It's a bit confusing since there is a mix of global vars (grid) yet needing to keep your state local to search() (14 Mar '12, 00:29) Matt Brown in addition it'd be better if the expected interface for the function (i.e. does it return a value, or just print a value and return nothing?) were better defined. For example, we should be able to see how the "grader" code will call our function. (14 Mar '12, 00:31) Matt Brown
 1 After many hours and much frustration I read this post link and found the trick: reset the code window, then be careful to only paste the search() code. It worked for me. Hopefully it will work for you too. I can't verify the presence of the 'hidden last line' but the above steps did the trick for me. Also my code returns to results and I use a print search() command. answered 13 Mar '12, 01:29 james gallagher 2.1k●4●12●56
 0 I took out and still the same problem. Does my code have to call the search () function at the end or not? Also , i inserted some functions before search() answered 12 Mar '12, 17:34 bumblesa 843●4●14●18
 0 same problem here. ( I'm defining "closed" & "opened" lists as either global or local variables and still no go). removing the comment did not do the trick either. answered 12 Mar '12, 17:38 animosity 325●4●6●12
 0 Hi, I have exactly the same problems. Its very frustrating. I have checked my code against all the examples in the lecture and i get the same answers for each. answered 12 Mar '12, 18:03 Scott Wilson-3 227●1●6
 0 I get the same problem. Mine works python browser & development python BUT not on submit. My code is not the same as the coded "proof" but it works. This type of thing is frustrating. answered 12 Mar '12, 18:11 Jim ODonnell 251●1●16
 0 I had the same problem, the code did seem to work but I still could not submit it. I have found the solution. Just a little hint: read well the instructions that are written at the beginning of the exercise. You should find something you have not done. Good luck! answered 12 Mar '12, 18:36 Jesús Pestan... 268●3●3●11
 0 To try and rule out any issues in my code I cut down the search function to: def search(): return [11,4,5] I am still getting "Incorrect. You may have incorrectly defined a function." I tried this a couple of times by pressing reset and then re-entering the code. Once when I tried it I got a message stating that my code did not work for a 7x6 matrix so this time it was accepted. However there was no obvious difference in the code that was accepted. answered 12 Mar '12, 18:50 david radnell 144●1●3 1 I got the same error, and it turned out it was caused by a hidden line in the web python console :-( The final lines I see are: # ---------------------------------------- # insert code here and make sure it returns the appropriate result  but there is still a hidden line, so you must insert your code after the whole comment block: # ---------------------------------------- # insert code here and make sure it returns the appropriate result # ----------------------------------------  It's very annoying my answer were marked as incorrect due to this bug. (13 Mar '12, 08:00) Fred G
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,207
×204