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%20chan-4's gravatar image

leo chan-4
2992310
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 Alex%20Brown-1's gravatar image

16 Answers:

12next »

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!

link

answered 12 Mar '12, 18:37

Tom%20Rijndorp-1's gravatar image

Tom Rijndorp-1
6421314

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 david%20radnell's gravatar image

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 josephks's gravatar image

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 Pax's gravatar image

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.

link

answered 13 Mar '12, 01:14

RoboCar2012's gravatar image

RoboCar2012
147310

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... Gregory%20Oschwald's gravatar image

Yeah! that trick worked fine. Thanks

(14 Mar '12, 08:48) escriva escriva's gravatar image

What if you also define some other functions?

(14 Mar '12, 12:46) Anne Paulson Anne%20Paulson's gravatar image

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 Curt%20Welch's gravatar image

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.

link

answered 13 Mar '12, 00:10

srparish's gravatar image

srparish
10436

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 Matt%20Brown's gravatar image

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 Matt%20Brown's gravatar image

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.

link

answered 13 Mar '12, 01:29

james%20gallagher's gravatar image

james gallagher
2.1k41256

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()

link

answered 12 Mar '12, 17:34

bumblesa's gravatar image

bumblesa
84341418

edited 12 Mar '12, 17:34

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.

link

answered 12 Mar '12, 17:38

animosity's gravatar image

animosity
3254612

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.

link

answered 12 Mar '12, 18:03

Scott%20Wilson-3's gravatar image

Scott Wilson-3
22716

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.

link

answered 12 Mar '12, 18:11

Jim%20ODonnell's gravatar image

Jim ODonnell
251116

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!

link

answered 12 Mar '12, 18:36

Jes%C3%BAs%20Pestana%20Puerta's gravatar image

Jesús Pestan...
2683311

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.

link

answered 12 Mar '12, 18:50

david%20radnell's gravatar image

david radnell
14413

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 Fred%20G's gravatar image
Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • 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

Tags:

×5,207
×204

Asked: 12 Mar '12, 17:14

Seen: 541 times

Last updated: 16 Mar '12, 01:23