# Homework 2 Questions

 0 Two questions about the homework: 1) I submitted the following answer for Homework 2.4 (blastoff): def countdown(n): while n > 0: print n n = n-1 return "Blastoff!" print countdown (10)  The only difference from the solution in the video, is that I used "return" instead of "print" in the final line of the problem. My answers was marked incorrectly. Can you explain why print is correct, but return was an incorrect answer? 2) I was also marked incorrectly for the answer I submitted for Homework 2.6 "Find Last" - while slightly less elegant that the solution in the answer video, this appears to do the same thing. Can you explain why this solution below was marked as incorrect?** def find_last(search_string, target_string): pos = search_string.find(target_string) while pos >= 0: increment = search_string.find(target_string,pos+1) if increment != -1: pos = increment else: break return pos print find_last("aaaa", "a")  Thanks - really enjoying the course. Hope you can take a look at these questions and provide some answers. Even if you are unable to change my grade, I would love to learn. David asked 12 Mar '12, 23:42 David-23 12●2 accept rate: 0%

 1 Was your code for 2.4 exactly as written, with irregular indentation? That might be enough to fail the automatic grading program. while should be indented and return should be at the same level of indentation as the while loop, like this: def countdown(n): while n > 0: print n n = n-1 return "Blastoff!"  Besides that, they may just be picky about making sure we know the distinction between printing a value (which returns None) and returning a value...even if the output looks the same when you run it. answered 12 Mar '12, 23:54 Frank Farach 691●1●4●12 Yes, they definitely require that "Blastoff!" be printed within the procedure, not returned and then printed externally. (13 Mar '12, 02:07) Kenneth I. L...
 0 Gotcha - thanks for the comments on my 1st question. Any ideas on the second one? answered 13 Mar '12, 04:13 David-23 12●2
 0 def find_last(text,such): last = -1 result = 0 while True: result = text.find(such,last+1) if result == -1: return last last = result  This was my solution and it returned as Correct! answered 13 Mar '12, 04:21 Kurt E. Spahn-2 183●1●3●9
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

×15,292
×74