Lab 4

In exercise number 1, I had to write a function that takes a string as an argument and displays the letters backward, one per line.

The code I wrote was:

prefixes = ‘FTJKDC’
suffix = ‘ree’

for letter in prefixes:
print letter + suffix

And the results were:

Capture

 

In exercise 3 I had to 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. 

The code I wrote was:

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def sigma(numbers):
sums = []
total = 0
for i in numbers:
total += i
sums.append(total)
print sums

sigma(numbers)

And the results were:

Capture

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *