Lab4

Lab Description: 

In this lab, the fist one in exercise 1 of Chapter 8 the program is to displays the letters backward and another one in exercise 3 of Chapter 10 the program is takes a list of numbers and returns the cumulative.

Code: 

exercise 1:

fruit = ‘orange’

index = len(fruit) – 1
while index >= 0:
letter = fruit[index]
print letter
index = index – 1

exercise 3:

def add_all(t):
add_all = []
total = 0
for i in t:
total = total + i
add_all.append(total)

return add_all
a = [2, 3, 4]
print(add_all(a))

Screenshot:

exercise1 chaper8screen ex1

exercise3 chaper10screen ex3

Leave a Reply

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