lab 4

Lab #4
Instructions:
Complete the following exercises from the online book:
• Exercise 1 of Chapter 8
• Exercise 3 of Chapter 10
Exercise 10.3. Write a function that takes a list of numbers and returns the cumulative sum; that
is, a new list where the ith element is the sum of the first i + 1 elements from the original list. For
example, the cumulative sum of [1, 2, 3] is [1, 3, 6].
Exercise 8.1. Write a function that takes a string as an argument and displays the letters backward,
one per line.

name = ‘raymond’
index = len(name) – 1
while index >= 0:
letter = name[index]
print letter
index = index – 1
d
n
o
m
y
a
r
>>> name = ‘raymond’
>>> len(name)
7
>>> len(name) – 1
6
>>>

def count(list1):
x = 0
total = 0
while x < len(list1): if x == 0: total = list1[x] print total x = x + 1 else: total = list1[x] + list1[x - 1] print total x = x + 1 return total print count([1,2,3,4,7]) 1 3 5 7 11 11