Test Index

Functions in Python Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 14 of 23
Marks: +1, -0
Predict the output of the following code :
def callon(b=20,a=10):
b=b+a
a=b-a
print(b,"#",a)
return b
x=100
y=200
x=callon(x,y)
print(x,"@",y)
y=callon(y)
print(x,"@",y)
[CBSE 2024 Set 4]
Solution:  
Output:
300 # 100
300 @ 200
210 # 200
300 @ 210
Explanation:
x = callon(100, 200): b = 100 + 200 = 300, a = 300 - 200 = 100. Prints 300 # 100 and returns 300, so x = 300.
print(x,"@",y) prints 300 @ 200.
y = callon(200): b = 200, a takes its default 10. b = 210, a = 210 - 10 = 200. Prints 210 # 200 and returns 210, so y = 210.
print(x,"@",y) prints 300 @ 210.
Key point: print() separates its items with a space by default, so a space appears on both sides of # and @.
© examsnet.com
Advertisements
Go to Question: