(a) Write the output of the code given below:

p=5

def sum(q,r=2):

global p

p=r+q**2

print(p, end= '#')

 

a=10

b=5

sum(a,b)

sum(r=5,q=1)

 

Answer:

Question 32(Choice 1)(a) -Teachoo.png

Output: 105#6#

Explanation:

In the first function call, a and b are passed as parameters. This assigns ‘q’ the value 10 and ‘r’ the value 5. This gives p the value 105 and it is printed with a ‘#’ after.

In the second function call, ‘q’ is assigned the value 1 and ‘r’ is assigned the value 5. This gives p the value 6. 

Now the output will be: 105#6#

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.