Function add – Two or more Integers

Function add – Two or more Integers: The program must accept five integers abcd and as the input. The program must print the values of a+ba+b+ca+b+c+d and a+b+c+d+e as the output.

Your task is to define the function add so that the program runs successfully.

Example Input/Output 1:
Input:
10 20 50 30 40

Output:
30
80
110
150

Explanation:
10 + 20 = 30.
10 + 20 + 50 = 80.
10 + 20 + 50 + 30 = 110.
10 + 20 + 50 + 30 + 40 = 150.

Example Input/Output 2:
Input:
2 4 8 6 5

Output:
6
14
20
25

def add(a,b,c=0,d=0,e=0):
    return a+b+c+d+e
a, b, c, d, e = map(int, input().split())
print(add(a, b))
print(add(a, b, c))
print(add(a, b, c, d))
print(add(a, b, c, d, e))
Previous Article

Define class Person

Next Article

Python Test : Variable names

Write a Comment

Leave a Comment

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