Error in evaluating homework 3.3 & 3.4

With all possible inputs & conditions I'm getting the expected outputs.
Still for both the questions of homework 3.3 & 3.4 its showing answer incorrect, though its output answer is correct.
When submitting 3.3 the output is --> "Incorrect. Your procedure did not return the correct value for a list of one element." though its returning correct value for one element list.
And the error for 3.4 is --> "Incorrect. Your procedure did not return the correct value for an empty list." though the procedure returns Zero for an empty list.
please do clarify this problem.

# Code for 3.3
def product_list(n):
    product = 1
    length = len(n)
    while length != 0:
        num = n.pop()
        product = num * product
        length = length - 1
    print product

# Code for 3.4
def greatest(p):
    max = 0
    for e in p:        
        if e > max:
            max = e
    print max        

asked 16 Mar '12, 02:08

Abulize's gravatar image


accept rate: 0%

edited 16 Mar '12, 07:05

Anton%20Golov's gravatar image

Anton Golov ♦

This was the answer I submitted for 3.4 and got graded as wrong when submitted. Please do point out the mistake if any.

(16 Mar '12, 02:25)


Abulize's gravatar image

3 Answers:

It looks like the problem with 3.3 is that it doesn't "return" the value of the product. In fact, if you print "product_list([1,2,3,6])" from the calling procedure, you'll find that it has the value "None"


answered 16 Mar '12, 02:24

Alan%20Kirschbaum's gravatar image

Alan Kirschbaum

k.thanx. Now i got ma mistake. Would have put return instead of print in both the answers.

(16 Mar '12, 02:28)


Abulize's gravatar image

See my answer above for 3.3. Same thing for 3.4 In addition, your code within the definition block needs to be indented (you probably did this, but it doesn't show up in the code snip that you posted.)


answered 16 Mar '12, 02:31

Alan%20Kirschbaum's gravatar image

Alan Kirschbaum

edited 16 Mar '12, 02:31

The question asked for a procedure to return the greatest number in the list.
You printed it. As venturaeagle said your indentation is wrong but I assume it is through the posting.


answered 16 Mar '12, 07:00

Michael%20Button's gravatar image

Michael Button

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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



Asked: 16 Mar '12, 02:08

Seen: 364 times

Last updated: 16 Mar '12, 07:05