Thursday, March 22, 2012

Python programming Day 03


#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

def product_list(my_list):
    if len(my_list)==1:
        return my_list[0]
    else:
        product=my_list[0]
        for i in range(len(my_list)-1):
            product=product*my_list[i+1]
    return product

No comments:

Post a Comment

Mounting USB drives in Windows Subsystem for Linux

Windows Subsystem for Linux can use (mount): SD card USB drives CD drives (CDFS) Network drives UNC paths Local storage / drives Drives form...