Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
237 views

Functions in Python MCQ

The document contains 32 questions related to functions in Python. The questions cover topics like return values from functions, default parameters, global vs local variables, variable scope, anonymous functions, and more. Example code snippets are provided to demonstrate function calls and behavior.

Uploaded by

Manpreet Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views

Functions in Python MCQ

The document contains 32 questions related to functions in Python. The questions cover topics like return values from functions, default parameters, global vs local variables, variable scope, anonymous functions, and more. Example code snippets are provided to demonstrate function calls and behavior.

Uploaded by

Manpreet Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

FUNCTIONS

ASSIGNMENTS
Q.1 If return statement is not used inside the function, then what value will be returned by
a function.
Q.2 What is the output of the following code?
def myfun(*name):
print('Hello', name)
myfun('my', 'school')
Q.3 What is the output of the following code?
numbers = [4, 5, 6]
newNumbers = tuple(map(lambda x: x , numbers))
print(newNumbers)
Q.4 Define a function which will find all such numbers which are divisible by 7 but are not a
multiple of 5,between 1000 and 3000 (both included)
Q.5 Define the same function of question no 4 where starting and ending number is passed
as argument
Q.6 Define a function that accepts a sentence and calculate the number of letters and digits
Q.7 Define a function that accepts a sentence and calculate the number of upper case
letters and lower case letters
Q.8 Define a function that can accept two strings as input and concatenate them and then
print it in console.
Q.9 Define a function which can generate and print a list where the values are square of
numbers between 1 and 20 (both included).
Q.10 With a given tuple (1,2,3,4,5,6,7,8,9,10), define a function to print the first half values
in one line and the last half values in one line.
Q.11 What is the output of the below program?
def myfunc(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
myfunc(3, 7)
myfunc(25, c = 24)
myfunc(c = 50, a = 100)
Q.12 What is the output of the below program?
x = 150
def myfunc():
global x
print('x is', x)
x=2
print('Changed global x to', x)
myfunc()
print('Value of x is', x)
Q.13 What is the difference between a parameter and an argument?
Q.14 Why is using the global statement a bad practice?
Q.15 How can we make a parameter of a function optional?
Q.16 What is the difference between local and global variables?
Q.17 Write a function called my_buzz that takes a number.
If the number is divisible by 3, it should return “Fizz”.
If it is divisible by 5, it should return “Buzz”.
If it is divisible by both 3 and 5, it should return “FizzBuzz”.Otherwise, same no.
Q.18 Write a function that returns the sum of multiples of 3 and 5 between 0 and limit
(parameter)
Q.19 Write a function that prints all the prime numbers between 0 and limit where limit is a
parameter.
Q.20 What Is The Output Of The Following Code Snippet?
x = 50
def func():
global x
print('x is', x)
x=2
print('Changed global x to', x)
func()
print('Value of x is', x)
Q. 22 What Is The Output Of The Following Code Snippet?
num = 1
def func():
global num
num = num + 3
print(num)

func()
print(num)
Q.23 What Is The Value Of Num After The Function Call?
def myfunc(text, num):
while num > 0:
num = num - 1

num=4
myfunc('Hello', num)

Q.24 What Is The Output Of The Following Code Snippet?


def testvarargs(farg, *args):
print ("formal arg:", farg)
for arg in args:
print ("another arg:", arg)
testvarargs(1, "two", 3)

Q.25 What Is The Name Given To That Area Of Memory, Where The System Stores The
Parameters And Local Variables Of A Function Call?
Q.26 What Is The Output Of The Following Code Snippet?
exp = lambda x: x ** 3
print(exp(3))

Q.27 Write a function func1() such that it can accept a variable length of argument and
print all arguments value
Q.28 Create a function that can accept two arguments name and age and print its value
Q.29 Create a function showEmployee() in such a way that it should accept employee
name, and it’s salary and display both, and if the salary is missing in function call it should
show it as 10000
Q.30 Write a function calculation() such that it can accept two variables and calculate the
addition and subtraction of it. And also it must return both addition and subtraction in a
single return call
Q.31 Predict the output of following python program:
r = lambda q: q * 3
s = lambda q: q * 2
x=2
x = r(x)
x = s(x)
x = r(x)
print x
Q.32 Predict the output of following python program:
count = 1

def doTask():

global count

for i in (1, 2, 3):


count += 1

doTask()

print (count)

You might also like