KnowledgeBoat Logo
|

Computer Science

Write the output of the code given below:

p=8
def sum(q=5, r=6) :
    p=(r+q)**2
    print(p, end= '#')
sum(p)
sum(r=3,q=2)

Python

Python Functions

2 Likes

Answer

Output
196#25#

Working

In the given code, the variable p is initially set to 8, and a function sum is defined with two parameters q and r, each having default values. When the function sum(p) is called, it overrides the default value of q with the value of p, resulting in q becoming 8. Inside the function, p is calculated as the square of the sum of q and r, which evaluates to 196. The function then prints 196# due to the end='#' parameter in the print statement. Subsequently, the function sum(r=3, q=2) is called with specific values for q and r, which are 2 and 3 respectively. Inside this call, p is calculated as 25 and printed as 25#. Therefore, the output of the code is 196#25#.

Answered By

2 Likes


Related Questions