# Homework 3.3 specification

 4 3 For Homework 3, exercise 3, the specification is as follows: #Define a procedure, product_list, #takes as input a list of numbers, #and returns a number that is #the result of multiplying all #those numbers together. #product_list([9]) => 9 #product_list([1,2,3,4]) => 24  My question is, do we have to handle an empty list input case ? (I mean, do we assume the list contains at least one element ?) asked 06 Mar '12, 22:41 Ioan-Victor ... 1.2k●4●15●41 accept rate: 63% fnenu-1 ♦♦ 18.5k●19●81●231 @PeterUdacity : as per standard english usage and mathematical meaning, shouldn't the procedure be called list_product instead ? (08 Mar '12, 10:38) Olivier GERARD

 9 Usually the product of no numbers is 1. That's more or less the reasoning behind  3**0 == 1  and even  0**0 == 1  which is a little easier to question. Similarly, the sum of no numbers is 0, thus  0*3 == 0  and  0*0 == 0  answered 06 Mar '12, 23:10 Larry Wilson 1.4k●4●12●22 fnenu-1 ♦♦ 18.5k●19●81●231 Of course, thank you. I really should sleep instead of coding. (07 Mar '12, 00:37) fnenu-1 ♦♦ My edit was to escape the * characters so they show up. (07 Mar '12, 00:38) fnenu-1 ♦♦ 8 If there was an empty list the result would be 1. I don't test it though. (07 Mar '12, 01:09) PeterUdacity ♦♦ 1 Interesting to see that Python indeed gives 0**0 == 1, while in mathematics zero to the power zero is considered undefined (07 Mar '12, 05:43) mrBB-4 Just to clarify @larry96's answer it's any_number**0 equal to 1 and as an example 3**1=0 (12 Mar '12, 06:08) Emilio Garcia-1
 2 I think the code should return 0 if it is empty [] but return the biggest if not empty. I have never heard of what you guys mean by the product of two zeros is 1. answered 07 Mar '12, 00:40 Eenvincible 3.6k●16●41●79 1 Not the product, the exponentiation. 0 raised to the 0-th power is 1. (07 Mar '12, 00:44) Larry Wilson @Eenvincible - I'm talking about HW 3.3, not 3.4 @larry96 - thanks, I'll return 1 until further notice. (07 Mar '12, 00:58) Ioan-Victor ...
 1 I have the same question: product_list([]) -> 1? or 0? answered 07 Mar '12, 05:18 renathy 17●2 It's 1. Check the comments under the accepted (green) answer. It won't be tested though. (07 Mar '12, 11:09) fnenu-1 ♦♦
 0 This(actually something similar) has been covered in a unit 3 quiz. answered 06 Mar '12, 23:01 elssar 19.5k●25●63●156 1 If you're referring to checking the length, I'm already doing that. If you're referring to the similar sum_list quiz problem, he returns 0 for an empty list, and for sums that would be correct, but for multiplying, you could argue 1 would be better (neutral for multiplication). I could also just return None or False or whatever. (07 Mar '12, 00:40) Ioan-Victor ...
 0 If we are supposed to handle it, what should the output be? At the moment my code returns 0 when it's empty, but should it return None or a message or what? Edit: now returning 1. Thanks @larry96 answered 06 Mar '12, 23:08 fnenu-1 ♦♦ 18.5k●19●81●231
 0 I have the same question, slothmaster. I currently have it returning 0, but would like some clarification. answered 06 Mar '12, 23:51 pseudonoob 200●3●12
 0 I have the same question: product_list([]) -> 1? or 0? If I have a product_list([0,1]) -> is 0? answered 08 Mar '12, 20:08 slin-1 98●1●1●12 product_list([]) -> 1 product_list([0,1]) -> 0 (since 0*1=0) (08 Mar '12, 20:09) fnenu-1 ♦♦
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,854
×1,718
×45