Is my solution to Homework 2.4 incorrect

I am getting the required result for the following code. But still I have been given wrong. what went wrong?

def countdown(n):
    i = 1
    while i <= n:
        print n
        n = n - 1
    return 'Blastoff!'

print countdown(4)

asked 08 Mar '12, 11:18

RAJESH%20KUMAR%20MAURYA-1's gravatar image

RAJESH KUMAR...
275
accept rate: 0%

edited 08 Mar '12, 11:33

Marek%20B%C3%A1lint's gravatar image

Marek Bálint
4.7k164285


3 Answers:

My quick answer was "You must print "Blastoff!", not return it. This has been covered in other question threads. Please check for that before starting a new thread."

However, I see that your question is deeper. You did print "Blastoff!" What is wrong with your answer is that the automatic grader will execute your countdown function only, rather than the whole of your code. Your interpretation of the problem statement is reasonable, but understanding the grading process will help you resolve such ambiguities.

link

answered 08 Mar '12, 11:20

Kenneth%20I.%20Laws-1's gravatar image

Kenneth I. L...
21.5k1976178

edited 08 Mar '12, 11:25

Ok accepted! I will be more careful in near future. Hope it goes well and average score remains above 70%. thanks for your prompt replay and explanation.

(08 Mar '12, 11:30) RAJESH KUMAR... RAJESH%20KUMAR%20MAURYA-1's gravatar image

We were asked to write a procedure that prints the numbers from n to 1 followed by the word "Blastoff!".

You have written a procedure that prints the numbers and returns the word "Blastoff!".

If it's called as the object of a print command, the output will look similar on the screen. But it's really not the same thing at all.

link

answered 08 Mar '12, 11:20

Lisa%20McLean's gravatar image

Lisa McLean
3.4k1435

You returned "Blastoff!" instead of printing it.

The countdown function should print everything without the use of a print statement to call it.

ex:

countdown(3)

3
2
1
Blastoff!
link

answered 08 Mar '12, 11:22

Marc-Andre%20Perreault's gravatar image

Marc-Andre P...
8717

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,253
×1,718
×160
×69
×3

Asked: 08 Mar '12, 11:18

Seen: 196 times

Last updated: 08 Mar '12, 11:33