Functions
Functions
2 Explain the use of global keyword used in function with the help of a
suitable example
a. 50 b. 0 c. Null d. None
What will be the output of the following code? 1
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),
my_func())
a. 100 200 b. 150 300 c. 250 75 d. 250 300
What will be the output of the following code? 1
Options :
(I) Pencil:Book (II) Pencil:Book
Eraser:Bag
(III) Pen:Book (IV) Bag:Eraser
Bag:Book
text="LearningCS"
L=len(text)
ntext=""
for i in range (0,L):
if text[i].islower():
ntext=ntext+text[i].upper()
elif text [i].isalnum():
ntext=ntext+text[i 1]
else:
ntext=ntext+'&&'
print(ntext)
3
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
What is the output of the following code snippet?
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
a) 5#8#15#4#
b) 5#8#5#4#
c) 5#8#15#14#
d) 5#18#15#4# 40
Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else: R=R+"#" print(R)
a. pYTHOn##@
b. pYTHOnN#@
c. pYTHOn#@
d. pYTHOnN@#
What will be the output of the following python code?
S=”Welcome”
def Change(T):
T=”HELLO”
print(T,end=’@’)
Change(S)
Print(s)
a) WELCOME@HELLO b)HELLO@HELLO
c)HELLO@WELCOME d)WELCOME@WELCOME
Identify the Correct possible output for the following Python Code:
import random
for N in range(2,5,2):
print(random.randrange(1,N),end=’#’)
a) 1#3#5# b)2#3#
c) 1#4# d) 1#3#
a) 20 # 50 @ 20 b) 50 @ 20 # 50
c) 50 # 50 # 50 d) 20 @ 50 # 20
a) Explain the use of positional parameters in a Python function with the help of a
suitable example.
(b) Explain the use of a default parameter in a Python function with the help of a
suitable example.
Write the output for the execution of the following Python code :
Write the definition of a function Sum3(L) in Python, which accepts a list L of integers and
displays the sum of all such integers from the list L which end with the digit 3.
For example, if the list L is passed
[ 123, 10, 13, 15, 23]
then the function should display the sum of 123, 13, 23, i.e. 159 as follows :
Sum of integers ending with digit 3 = 159