0% found this document useful (0 votes)
15 views7 pages

Python User Defined Functions Quiz

The document provides a series of questions and answers related to user-defined functions in Python, covering topics such as function definition, calling functions, and expected outputs of various code snippets. It includes multiple-choice questions and code examples to test understanding of Python functions. The content is structured as a quiz format, aimed at assessing knowledge of Python programming.

Uploaded by

kvvgrvidyalaya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Python User Defined Functions Quiz

The document provides a series of questions and answers related to user-defined functions in Python, covering topics such as function definition, calling functions, and expected outputs of various code snippets. It includes multiple-choice questions and code examples to test understanding of Python functions. The content is structured as a quiz format, aimed at assessing knowledge of Python programming.

Uploaded by

kvvgrvidyalaya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

User Defined Functions in Python

2. What is the output of the following code? def display(msg): print(msg, 'is a habit.')
display('Creativity')
(1 Point)

is a habit

Creativity is a habit.

is a habit. Creativity

Creativity
[Link] python which keyword is used to start function?
(1 Point)

function

import

def

try
[Link] of the following function headers is correct?
(1 Point)

def fun(a = 2, b = 3, c)

def fun(a = 2, b, c = 3)

def fun(a, b = 2, c = 3)

def fun(a, b, c = 3, d)
[Link] one of the following is the correct way of calling a function?
(1 Point)

function_name()

call function_name()

ret function_name()

function function_name()
[Link] a command to call a function def dispMesg(): num=5 print(num+5)
(1 Point)
dispMesg

dispMesg(num)

dispMesg()

def dispMesg()
[Link] is the output of the add() function call def add(a, b): return a+5, b+5 result = add(3, 2)
print(result)
(1 Point)

(8,7)

15

7
[Link] the output def calc(num) if num%2 == 0: print(num+5) else print(num*5) calc(7)
(1 Point)

35

12

0
[Link] the output: def calc(num) sum=0 for i in range (1,num,2): sum=sum+i print(sum) calc(5)
(1 Point)

4
[Link] will be the output of the following Python code? def func(): return num *5 num = 5
print(func())
(1 Point)

25
5

error

10
[Link] will be the output of the following Python code? def f1(): global x x+=1 x=10 f1() print(x)
(1 Point)

11

10

error

12
[Link] will be the output of the following Python code? x=100 def f1(): global x x=90 def f2():
x=80 f1() f2() print(x)
(1 Point)

100

90

error

80
[Link] will be the output of the following Python code? x=100 def f1(): x=90 def f2(): x=80 f1()
f2() print(x)
(1 Point)

100

90

error

80
[Link] and write the output of the following python code: def fun(s): k=len(s) m=" " for i in
range(0,k): if(s[i].isupper()): m=m+s[i].lower() elif s[i].isalpha(): m=m+s[i].upper() else: m=m+'bb'
print(m) fun('school2@com')
(1 Point)

schoolbbbbcom

schoolbbcom
SCHOOLbbbbCOM

school@com
[Link] and write the output of the following python code: def Change(P ,Q=30): P=P+Q Q=P-Q
print( P,"#",Q) return (P) R=150 S=100 R=Change(R,S) print(R,"#",S) S=Change(S)
(1 Point)

150 # 250

150 # 100

100 # 130

250 # 150

250 # 100

130 # 100
[Link] and write the output of the following python code: a=10 def call(): global a a=15 b=20
print(a) call()
(1 Point)

20

35

15

10
[Link] and write the output of the following python code: x = 50 def func(x): x = 2 func(x) print('x
=', x)
(1 Point)

x=50

x=2

x=100

x=52
[Link] and write the output of the following python code: x = 50 def func(): global x x = 2 func()
print('x=', x)
(1 Point)
x=50

x=2

x=100

x=52
[Link] and write the output of the following python code:

def calcresult () :
i=9
x=0
while i> 1 :
if (i % 2 == 0):
x = i%2
i = i-1
else :
i = i-2
x=i
print (x**2)

calcresult()
(1 Point)

49

25

1
[Link] and write the output of the following python code: def makenew(mystr): newstr = " " count
= 0 for i in mystr: if count%2 !=0: newstr = newstr+str(count) else: if [Link](): newstr =
newstr+[Link]() else: newstr = newstr+i count +=1 newstr = newstr+mystr[:1] print ("The new
string is :",newstr) makenew(“sTUdeNT")
(1 Point)

The new string is : STUDENTs

The new string is: S1U3E5Ts

The new string is: STUDE5tS

The new string is: StuDE5Ts


[Link] and write the output of the following python code: def ChangeList(): L=[] L1=[] L2=[] for i
in range (1,10): [Link](i) for i in range(10,1,-2): [Link](i) for i in range(len(L1)):
[Link](L1[i]+L[i]) [Link](len(L)-len(L1)) print (L2) ChangeList()
(1 Point)

[11, 10, 9, 8, 4, 7]

[11, 10, 9, 8, 7, 4]

[11, 10, 9, 8, 7, 3]

[11, 10, 9, 8, 6, 4]
[Link] and write the output of the following python code: def FindOutput(): L="earn" X="" L1=[]
count=1 for i in L: if i in ['a','e','i','o','u']: X=X+[Link]() else: if (count%2!=0):
X=X+str(len(L[:count])) else: X=X+i count=count+1 print(X) FindOutput()
(1 Point)

Ea3n

EA3N

EA3n

eA3n
[Link] and write the output of the following python code: def func(a, b=5, c=10): print('a =', a, ',b
=', b, ', c =', c) func(3, 7) func(25, c = 24) func(c = 50, a = 100)
(1 Point)

a = 3 , b = 7 , c = 10

a = 25 , b = 5 , c = 24

a = 15 , b = 100 , c = 50

a = 25 , b = 100 , c = 7

a = 5 , b = 10 , c = 50

a = 100 , b = 5 , c = 50

a = 5 , b = 100 , c = 50
[Link] and write the output of the following python code: def power(x, y=2): r = 1 for i in range(y):
r = r * x return r print (power(3)) print (power(3, 3))
(1 Point)

9
6

27
1 2 3 4 5 6 7 8 9 1 1 1 1 1 15 1 1 1 1 2 2 2 23 24
0 1 2 3 4 6 7 8 9 0 1 2
B C C A C A B D A A B A C DE C A B D B C C AB B
F E C

You might also like