AMS 209: HW 4: Problem 4ΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# coding: utf8

'''
Created on October 31st, 2017

@author: Geetanjali
'''

def cumulative_sum(num_list):
	"""
	:param num_list: the list of numbers whose cumulative sum is to be found
	:return num_list: the list passed as argument is returned with the cumulative sum of all the elements appended as the last element
	"""

	new_element = 0
	for i in range(0, len(num_list)):
		new_element = new_element+num_list[i]
	num_list.append(new_element)
	return(num_list)


if __name__ == '__main__':
	num_list = []

	print("Enter a list: (just enter a non-numeric character to stop)")
	while(True):
		user_input = input()
		if(user_input.isdigit()):
			num_list.append(int(user_input))
		else:
			break
	print(cumulative_sum(num_list))