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
product_list([1,2,3,6])

# Code for 3.4
def greatest(p):
    max = 0
    for e in p:        
        if e > max:
            max = e
    print max        
greatest([1,5,3,9,4,9,10,2,4])

asked 16 Mar '12, 02:08

Abulize's gravatar image

Abulize
012

accept rate: 0%

edited 16 Mar '12, 07:05

Anton%20Golov's gravatar image

Anton Golov ♦
13.8k2175174

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

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"

link

answered 16 Mar '12, 02:24

Alan%20Kirschbaum's gravatar image

Alan Kirschbaum
1.1k1626

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

(16 Mar '12, 02:28)

Abulize

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

link

answered 16 Mar '12, 02:31

Alan%20Kirschbaum's gravatar image

Alan Kirschbaum
1.1k1626

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.

link

answered 16 Mar '12, 07:00

Michael%20Button's gravatar image

Michael Button
1.6k2731

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

×30,792
×1,800
×46
×34

Asked: 16 Mar '12, 02:08

Seen: 367 times

Last updated: 16 Mar '12, 07:05