Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

(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#

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.