Lab Description:
This example is to write a function that takes a string as an argument and displays the letters backward, one per line. The next example for excercise 3, is to write 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].
Code:
name = input(‘enter a name: ‘) len_name = len(name) name_rev = name[len_name – 1] print(name_rev) len_name = len_name-1
while len_name != 0: name_rev = name[len_name – 1] print (name_rev) len_name = len_name – 1
#Excersise 3
def add_all(t): total = 0 for x in t: total = total + x return total
t = [1, 2, 4, 8, 16] sum (t)
ScreenShots: