wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

functions in python class 12 vaishali

Total questions: 50

Worksheet time: 29mins

Name
Class
Date
1.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
2.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
3.
What will print?
a)
nothing
b)
7
c)
z
d)
12
4.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
5.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
6.
What will print?
a)
1 2
b)
1
c)
3
d)
5
7.

What term is used to describe data passed into a function?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

8.

Leo wants to create a function that will roll a dice. Which is the correct function definition header?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []:

9.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

10.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

11.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

12.

Python supports variable number of parameters.

a)

True

b)

False

13.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

14.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

15.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

none of the above

16.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

17.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

18.

Which of the following is the use of id() function in python?

a)

Id returns the identity of the object

b)

Every object doesn’t have a unique id

c)

All of the mentioned

d)

None of the mentioned

19.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

a)

[3, 4, 5, 20, 5, 25, 1, 3]

b)

[1, 3, 3, 4, 5, 5, 20, 25]

c)

[3, 5, 20, 5, 25, 1, 3]

d)

[1, 3, 4, 5, 20, 5, 25]

20.

Write the line of code that will call the function.

(a)  

21.

Write the line of code that will define the function, draw_coin

(a)  

22.

Do you call or define a function first?

a)

call

b)

define

23.

Rewrite this line of code correctly!

(a)  

24.

Rewrite this line of code correctly!

(a)  

25.

In the code given, a function was defined. Now write the code to call the function.

(a)  

26.

Rewrite the line of code that is written incorrectly to make it correct!


Hint: The mistake is when the function gets called

(a)  

27.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
28.

A variable that can be accessed from anywhere in a program is called

(a)  

29.

Which keyword marks the beginning of the function block

a)

Func

b)

Define

c)

def

d)

Function

30.

What will be the output of this program?


def addOne(number):

number += 1

return number

one = addOne(0)

two = addOne(one)

print(two)

a)

0

b)

1

c)

2

d)

3

e)

4

31.

What will be the output of this program?


def hello():

print(“I am a beginner”)

hello()

hello()

a)

I am a beginner

b)

I am a beginner I am a beginner

c)

Hello

d)

Hello

Hello

e)

I am a beginner

I am a beginner

32.

When a variable is inside of a function what do you call its scope?

a)

Static

b)

Local

c)

Global

d)

Boolean

33.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger

34.

What is the default return value of a function that does not return any value explicitly?

a)

Int

b)

Float

c)

Double

d)

None

35.

What does the function header contain?

a)

The function name

b)

The function name and parameter list

c)

The parameter list

d)

The return value

36.

The output of the code above will be

a)

0

b)

1

c)

99

37.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function

38.

What will be the output of the following Python code?

def cube(x):

return x * x * x


x = cube(3)

print (x)

a)

9

b)

3

c)

27

d)

30

39.

What is a variable defined inside a function referred to as?

a)

A global variable

b)

A volatile variable

c)

A local variable

d)

An automatic variable

40.

What is the output of the below program?

a)

x is 50Changed global x to 2Value of x is 50

b)

x is 50Changed global x to 2Value of x is 2

c)

x is 50Changed global x to 50Value of x is 50

d)

None of the mentioned

41.

What is the output of the function shown below (random module has already been imported)?


random.choice('sun')

a)

sun

b)

either s,u or n

c)

u

d)

Error

42.

Which of the following function headers is correct?*

a)

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

b)

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

c)

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

d)

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

43.

Which of the following functions is a built-in function in python?

a)

array()

b)

sqrt()

c)

factorial()

d)

print()

44.

What will be the output of the following Python expression? round(4.576)

a)

4.5

b)

5

c)

4

d)

4.6

45.

A Python module is a file with the _____ file extension that contains valid Python code.

a)

.pym

b)

.pymodule

c)

.module

d)

.py

46.

What is returned by math.ceil(3.4)?

a)

3

b)

4

c)

4.0

d)

3.0

47.

Which statement is correct to import all modules from the package

a)

from package import all

b)

from package import *

c)

from package include all

d)

from package include *

48.

4. The code block of function always comes after a _______.

a)

;

b)

:

c)

'

d)

#

49.

What term is used to describe data passed into a function?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

50.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above