Exercise 1
Description:
This code takes a word and displays it backwards
Code:
color = 0
while color < len(“black”):
black = “black”[-1+color *-1]
print black
color = color + 1
Picture:
Exercise 3
Description:
This is function that takes a list of numbers and returns the cumulative sum. for example the cumulative sum of [1, 2, 3] is [1, 3, 6].
Code:
def cumulative(a):
cumulative = []
add = 0
for x in a:
add += x
cumulative.append(add)
return cumulative
a = [10, 5, 10]
print(cumulative(a))
a = [5,6,7]
print(cumulative(a))
a = [45,20,15]
print(cumulative(a))
Picture: