Lab Description:
This program is based on strings and lists. The first one is a function that takes a string and displays it backwards from the last character to the first. The second one is a function the takes a list and displays the accumulative sum. The second program was more difficult to write than the first.
Code:
Exercise 1, Chapter 8
def backward(x): index=-1 length=(-1*len(x)) while index >= length: letter = x[index] print (letter) index = index -1 print (backward("dg4346534"))
Exercise 3, Chapter 10
def accum(x): y=x index=1 post=0 y[0]=x[0] y[index]=x[post]+x[index] while post<index: index=index+1 post=post+1 if index==len(x): print (y) break y[index]=y[post]+x[index] t=[1,2,3,4,5,6,7,8] accum(t)
Screenshots:
exercise 1, Chapter 8
Exercise 3, Chapter 10