Robotics & Artificial Intelligence

Predict the output of the following code:

def Sum(a, b):
    return a+5, b*5
# main program
result = Sum(4, 5)
print(result)

Python Functions

1 Like

Answer

Output
(9, 25)
Explanation

The function Sum() is called with the values 4 and 5. Inside the function, the expression a+5 becomes 4+5 = 9 and the expression b*5 becomes 5*5 = 25. The return statement sends both values back to the main program. In Python, when multiple values are returned together, they are stored as a tuple. Therefore, the variable result stores the tuple (9, 25), which is displayed by the print(result) statement.

Answered By

3 Likes


Related Questions