"Incorrect. Something went wrong while running your procedure" - not for me!

 0 Homework 2.6, I answered as follows (albeit belatedly, as I was away in Geneva. I assume now that I'll have to opt for the final making 100%, otherwise the 50% for homework will be brought down by the 0% grade here?): def find_last(search,target): result = search.find(target) while result != -1: last = result result = search.find(target,last+1) return last  I then get this error on submission: Incorrect. Something went wrong while running your procedure. Well, certainly not when I run it! Any ideas why I'm getting this error? Would also appreciate knowing what will happen about the homework situation, I couldn't avoid missing the deadline - but it's also frustrating to have overall grade completely hanging on final exam. Thanks. asked 09 Mar '12, 12:35 OJFord 76●1●4●12 accept rate: 37% Rob Barnes-3 ♦ 19.1k●10●68●205

4 Answers:
 1 Your code does not assign anything to last if the target string does not exist in the search string, so it's attempting to return a value that it can't find, which gives an error. A suggestion: include a line that tests for that exact case and return -1 if the target isn't present. As for the homework, one homework grade is dropped, so if this is the only homework you miss, your homework grade can still be averaged in with your final. answered 09 Mar '12, 12:38 David Harris 8.1k●21●55●111
 2 Your code doesn't terminate properly if it doesn't enter the while loop. Also I had to edit your post to fix your code formatting. When you post code, you want to make sure it's formatted properly so we can read it. Please review this post if you need to know how to format your code for the forums. Remember to test against multiple cases (as the grader does) rather than just one or two. Try to cover all the possible types of inputs that you expect. Try running your code against these: print (find_last('aaaaa', 'aa')) print find_last('aaaa', 'a') print find_last('aaaa', 'b') print find_last("111111111", "1") print find_last("222222222", "") print find_last("", "3") print find_last("", "") print find_last('ballplayers play ballgames.','ball')  Regarding the homework: The new policy is: if your final exam score is better than your homework average, your final grade for the course will just be your score on the final. Otherwise your grade will be the average of your grade for the final and your grade for the homework. answered 09 Mar '12, 12:41 Rob Barnes-3 ♦ 19.1k●10●68●205
 0 Ah, thanks. Sorted. Edit: Thanks Valek too. Just saw your reply. I definitely should have checked for more circumstances.. but I just couldn't see where it was missing before forbiddenvoid pointed it out. Thanks again. answered 09 Mar '12, 12:53 OJFord 76●1●4●12
 0 Okay sorry for this, but I must be incredibly tired, or something. I'm having the same issue with my answer to HW 2.7: def print_multiplication_table(n): i = 1 while i < n: print str(i) + ' * ' + str(i) + ' = ' + str(i * i) print str(i) + ' * ' + str((i+1)) + ' = ' + str(i * (i+1)) print str((i+1)) + ' * ' + str(i) + ' = ' + str((i+1) * i) i += 1 print str(n) + ' * ' + str(n) + ' = ' + str(n * n)  I can't see any problem with it, no matter how many numbers I put in for n. answered 09 Mar '12, 13:17 OJFord 76●1●4●12
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:

×15,234
×683
×192
×66
×23

Asked: 09 Mar '12, 12:35

Seen: 118 times

Last updated: 09 Mar '12, 13:17