kode2go / python

Lessons on learning python programming.
0 stars 0 forks source link

Python Exercises: Q5 #5

Open kode2go opened 3 years ago

kode2go commented 3 years ago
  1. Using myList = [1981,2004,1999,2010,1989]

5a. Write a Python program to sum all the items in myList.

5b. Write a Python program to multiply all the items in myList.

kode2go commented 3 years ago
myList = [1981,2004,1999,2010,1989]

#a
print(myList[0]+myList[1]+myList[2]+myList[3]+myList[4])

sumList = sum(myList) 
print(sumList)
sumList2 = 0
for num in myList:
     sumList2 = sumList2 + num

 print(sumList2)

#b
print(myList[0]*myList[1]*myList[2]*myList[3]*myList[4])

mulList2 = 1
for num in myList:
    mulList2 = mulList2 * num

print(mulList2)