Lab 4

 

print(“————String———–”)
# Ask the user to input a name and print the reverse of it
name1 = raw_input(‘Enter a name: ‘)
index = len(name1) – 1
while index >= 0:
x = name1[index]
print x
index = index – 1

 

print(“————-List————”)

# Ask user to enter 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.

def add_all(names):
n = (n1+n2)
na = (n +n3)
nb = (na + n4)
t = [n1,n,na,nb]
return t

n1 = input(‘Enter first number: ‘)
n2 = input(‘Enter second number: ‘)
n3 = input(‘Enter third number: ‘)
n4 = input(‘Enter fourth number: ‘)

names = [n1,n2,n3,n4]

print ‘The cumulative sum of’,names,’is’,add_all(names)

Leave a Reply

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