Chapter 2: Memory Management

Example 1, page no. 19

In [2]:
print "Enter the number of element(s) to be added: "
n = int(raw_input())
nos = []
for i in range(1,n+1):
    print "Enter the %d element: " %i
    nos.append(int(raw_input()))

sum = 0
for i in range(0,n):
    sum += nos[i]

print "The SUM of no(s) is: %d" %sum
Enter the number of element(s) to be added: 
4
Enter the 1 element: 
1
Enter the 2 element: 
2
Enter the 3 element: 
3
Enter the 4 element: 
4
The SUM of no(s) is: 10