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
2 Likes
Related Questions
Predict the data type of the given Python statement:
n=0.0025 print(type(n))Predict the output of the following code:
def Add(num1, num2): sum = num1 + num2 sum = Add(20, 30) print(sum)Predict the output of the following code:
def Disp_Max(a, b): if a > b: print(a, 'is maximum') elif a == b: print(a, 'is equal to', b) else: print(b, 'is maximum') Disp_Max(22, 14)Assertion (A): When the user defines a function of his/her own and use it in the program to perform a specific task, it is known as user defined function.
Reason (R): The types of functions viz. built-in functions and modules are also known as user defined functions because they are not defined by the system developers. Thus, it is not necessary that the system developers are only authorised for creating a function.
Based on the above discussion, choose an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.