Unseen Passage

For Class 4 to Class 12

Python Fundamentals Class 11 Computer Science Important Questions

Please refer to Python Fundamentals Class 11 Computer Science Important Questions with answers below. These solved questions for Chapter 2 Python Fundamentals in NCERT Book for Class 11 Computer Science have been prepared based on the latest syllabus and examination guidelines issued by CBSE, NCERT, and KVS. Students should learn these solved problems properly as these will help them to get better marks in your class tests and examinations. You will also be able to understand how to write answers properly. Revise these questions and answers regularly. We have provided Notes for Class 11 Computer Science for all chapters in your textbooks.

Important Questions Class 11 Computer Science Chapter 2 Python Fundamentals

All Python Fundamentals Class 11 Computer Science Important Questions provided below have been prepared by expert teachers of Standard 11 Computer Science. Please learn them and let us know if you have any questions.

Question. What is the area of memory called which stores the parameters and local variables of a function call?
(a) A Heap
(b) Storage area
(c) A Stack
(d) An Array

Answer

C

Question. Which of the following is the use of function in python?
(a) Functions are reusable pieces of programs
(b) Functions don’t provide better modularity for your application
(c) you can’t also create your own functions
(d) All of the mentioned

Answer

A

Question. Which of the following function is a built in function?
(a) seed()
(b) from()
(c) sqrt()
(d) for()

Answer

C

Question. What is the output of the expression?
round(4.5676,2)
(a) 4.5
(b) 4.6
(c) 4.57
(d) 4.56

Answer

C

Question. What is the output of the below program?
def C2F(c):
return c * 9/5 + 32
print C2F(100)
print C2F(0)
(a) 212 and 32
(b) 314 and 24
(c) 567 and 98
(d) None of the mentioned

Answer

A

Question. The flow of execution refers to the _____ in which statements are executed during a program run.
(a) Number
(b) Type
(c) Order
(d) Value

Answer

C

Question. What is the output of the below program?
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)
(a) x is 50 Changed global x to 2 Value of x is 50
(b) x is 50 Changed global x to 2 Value of x is 2
(c) x is 50 Changed global x to 50 Value of x is 50
(d) None of the mentioned

Answer

B

Question. What are the outcomes of the functions shown below?
Sum(2,4,6)
Sum([1,2,3])
(a) Error, 6
(b) 12, Error
(c) 12, 6
(d) Error, Error

Answer

A

Question. The function definition does not execute –
(a) Function body
(b) Parameters
(c) Function Header
(d) All of the above

Answer

A

Question. What is the output of below program?
def say(message, times = 1):
print(message * times)
say(‘Hello’)
say(‘World’, 5)
(a) Hello and WorldWorldWorldWorldWorld
(b) Hello and World 5
(c) Hello and World,World,World,World,World
(d) Hello and HelloHelloHelloHelloHello

Answer

A

Question. Consider the following function call statement:
Multiply(p,5)
here p and 5 are ?
(a) variable and expression argument
(b) literal and variable argument
(c) variable argument and literal
(d) None of the above

Answer

C

Question. Which keyword is use for function?
(a) Fun
(b) Define
(c) def
(d) Function

Answer

C

Question. What is the order of resolving scope of a name in a Python program?
(L: Local namespace, E: Enclosing namespace, B: Builtin namespace, G: Global namespace)
(a) B G E L
(b) L E G B
(c) G E B L
(d) L B E G

Answer

B

Question. What is the output of the code shown below?
e=”butter”
def f(a):
print(a)+e
f(“bitter”)
(a) error
(b) butter error
(c) bitter error
(d) bitterbutter

Answer

D

Question. Where is function defined?
(a) Module
(b) Class
(c) Another function
(d) All of the mentioned

Answer

D

Question. How are default arguments specified in the function heading?
(a) identifier followed by an equal to sign and the default value
(b) identifier followed by the default value within backticks (“)
(c) identifier followed by the default value within square brackets ([])
(d) identifier

Answer

A

Question. What is the error in the following code: def fun(a=1,b): ?
(a) Non default arguments cannot follow default arguments
(b) Non default arguments can follow default arguments
(c) No error
(d) Invalid syntax

Answer

A

Question. What is the output of this code?
def f():
x=4
x=1
f()
(a) Error
(b) 4
(c) Junk value
(d) 1

Answer

D

Short Answer Type Questions

Question: What is return by following code?
(i) math.ceil(8.7)
(ii) math.floor(9.5)
Answer: (i) 9 (ii) 9

Question: What will be the output of the given code?
import random
random.randrange (1, 50, 10)
Answer: The output of this code can be any value which is a multiple of 10, plus 1. Hence, a variable like 11, 21, 31, 41 can be output. Also, the value should necessarily be between 1 and 50.

Question: Write the short note on
(i) ceil() (ii) floor()
Answer: (i) ceil() method returns ceiling value of x i.e, the smallest
integer not less than x.
Syntax math.ceil(x)
(ii) floor() method is used to return a value which is less than or equal to a specific expression or value.
Syntax math.floor(x)

Question: What is the output of the given code?
(i) int (math.pow (5, 3))
(ii) math.pow(5, 3)
(iii) int (pow(5, 3, 4))
Answer: (i) 125 (ii) 125.0 (iii) 1

Question: What is the output of the given code?
from random import shuffle
x = [‘One’,‘Two’, ‘Three’, ‘Four’, ‘Five’,
‘Six’]
shuffle(x)
print(x)
Answer: Output [‘Four’, ‘Five’, ‘Two’, ‘Six’, ‘One’, ‘Three’]

Question: How can you generate random numbers in Python?
Answer: random module is the standard module that is used to generate a random number. The method is defined as import random random.random() The statement random.random() returns the floating point number that is in the range of (0, 1). The function generates random float numbers. The methods that are used with the random class are the bound methods of the hidden instances.

Question: How to import entire module in Python?
Answer: To import entire module, import statement is used. import statement is also used to import selecting modules.
Syntax import module_name When we import a module, we are making it available to us in our current program as a separate namespace.

Question: Define the sqrt() method with an example.
Answer: sqrt() method is used to find the square root of a specified expression or an individual number, math module is used to import this function.
Syntax import math
math.sqrt(number)
e.g.
>>>import math
>>> math.sqrt(25)
5.0
>>> math.sqrt(16.9)
4.110960958218893

Question: What things take place internally, when from <module> import <object> command is used?
Answer:
♦The code of module which imported is interpreted and executed.
♦ When module is imported, only mentioned functions and variables are available to the program.
♦ In the current namespace, the imported definition is added because no new namespace is setup.

Question: Distinguish between floor() and ceil().
Answer: Differences between floor() and ceil() are as follows

 Long Answer Type Questions

Question: What is the output of the given code?
import statistics
from fractions import fraction as F
from decimal import decimal as D
a = statistics.mean ([11, 2, 13, 14, 44])
b = statistics.mean ([F(8, 10), F(11, 20), F(2,
5), F(28, 5)])
c = statistics.mean ([D(“1.5”), D(“5.75”),
D(“10.625”), D(“2.375”)])
print (“Simple mean:”, a)
print (“Fraction mean:”, b)
print (“Decimal mean:”, c)
Answer: Output
Simple mean : 16.8
Fraction mean: 147/80
Decimal mean: 5.0625

Question: Predict the output.
import math
print (“cos:”, math.cos(1.047197551))
print (“sin:”, math.sin(0.523598775))
print (“tan:”, math.tan(0.463647609))
print (“degree:”, math.degrees(3.1415926))
print (“radian:”, math.radians(180))
Answer: Output
cos : 0.5000000001702586
sin : 0.4999999994818579
tan : 0.49999999999899236
degree : 179.99999692953102
radian : 3.1415926535489793

Question: Find the output of the following code.
import math
print (“ceil:”, math.ceil (5.24))
print (“fabs:”, math.fabs (5.24))
print (“fabs:”, math.fabs (–5.24))
print (“floor:”, math.floor (–5.24))
print (“pow:”, math.pow (3, 5))
print (“round:”, round (3.14159))
print (“round:”, round (3.14159,3))
print (“sqrt:”, math.sqrt (64))
Answer: Output
ceil: 6
fabs: 5.24
fabs: 5.24
floor: – 6
pow: 243.0
round: 3
round: 3.142
sqrt: 8.0

Question: Predict the output.
import statistics
list = [5, 2, 5, 6, 1, 2, 6, 7, 2, 6, 3, 5, 5]
x = statistics.mean (list)
print (x)
y = statistics.median (list)
print (y)
z = statistics.mode (list)
print (z)
Answer: Output
4.230769230769231
5
5

Question: Modules refer to a file containing Python statements and definitions. A file containing Python code, for example : example.py, is called a module, and its module name would be example. We use modules to break down large programs into small manageable and organised files. Furthermore, modules provide reusability of code. Module focuses on small proportion of the problem, rather than focusing on the entire problem.
(i) The output of the following code is either 1 or 2. 
State whether this statement is true or false.
import random random.randint (1, 2)
(ii)What is module in Python?
(iii)Which function is equivalent to random. randint (4, 7)?
(iv)What is return by math.floor (−20.0)?
(v) How to import modules in Python?
Answer: (i) True
(ii) Modules can define functions that you can reference in other Python files.
(iii) 4 + random. randrange (4) on return any one of 4, 5, 6 and 7.
(iv) 20
(v) Modules can be imported using the import keyword.

Question: Define the random module in Python.
Answer: Python offers random module that can generate random numbers. There are various types of random functions which can import by random keyword.
Some of them are describe below
(i) random() This method is used to generate a float random number less than 1 and greater than or equal to 0. It does not require any parameters.
Syntax random.random()
(ii) randint() This method is one of methods that handles random numbers. It has two parameters start and end generate an integer between start and end (including both).
Syntax random.randint(start, end)
(iii) randrange() This method returns a random selected element from the range created by the start, stop and step arguments. By default, the value of start is 0 and the value of step is 1.
Syntax random.randrange(start, stop, step)
(iv) choice() This method is used to generate 1 random number from a container.
Syntax random.choice(sequence)
(v) shuffle() This method randomly reorder the elements in a list. It can shuffle only list elements.
Syntax random.shuffle(list)

Question: Write a program to input any two matrices and print product of matrices.
Answer: import random
m1 = int(input (“Enter number of rows in first matrix”))
n1 = int(input (“Enter number of columns in first
matrix”))
a = [[random.random () for row in range (m1)] for col in
range (n1)]
for i in range (m1):
for j in range (n1):
a[i][j] = int(input ())
m2 = int(input (“Enter the number of rows in the second
matrix”))
n2 = int(input (“Enter the number of columns in the second
matrix”))
b = [[random.random () for row in range (m2)] for col in
range (n2)]
for i in range (m2):
for j in range (n2):
b[i][j] = int(input ())   
c = [[random.random () for row in range (m1)] for col in
range (n2)]
if (n1 == m2):
for i in range (m1):
for j in range (n2):
c[i][j] = 0
for k in range (n1):
c[i][j] += a[i][j]*b[i][j]
for s in c:
print(s)
else:
print(“Multiplication is not possible”)

Question: Write a program to input any two matrices and print sum of matrices. 
Answer: import random
m1 = int(input (“Enter total number of rows in the first
matrix”))
n1 = int(input (“Enter total number of columns in the
first matrix”))
a = [[random.random() for row in range(m1)] for col in
range (n1)]
for i in range (m1):
for j in range (n1):
a[i][j] = int(input())
m2 = int(input (“Enter total number of rows in the second
matrix”))
n2 = int(input (“Enter total number of columns in the
second matrix”))
b = [[random.random () for row in range (m2)] for col in
range (n2)]
for i in range (m2):
for j in range (n2):
b [i][j] = int(input ())
c = [[random.random () for row in range (m1)] for col in
range (n1)]
if ((m1 == m2) and (n1 == n2)):
print(“Output is”)
for i in range (m1):
for j in range (n1):
c[i][j] = a[i][j] + b[i][j]
for s in c:
print(s)
else:
print(“Matrix addition is not possible”)

Case Based Questions :

Arpita of class XII was writing a function code but missed some lines in between. Help her to complete the code
……… func(message, num=1): #line 1
……(message*num) #line 2
…………..

Question. Line 2 missed :
(a) input
(b) print
(c) for
(d) if

Answer

B

Question. In Line 3 what she need to write to call a function?
(a) func( )
(b) func(‘Python’)
(c) func(‘Python’, 3)
(d) Both b and c

Answer

D

Question. Line 1 will be replaced by:
(a) call
(b) def
(c) invoke
(d) None

Answer

B

Ankit have a group of 3 friends. One day they learn about functions used in Python. They started their discussion on its use , scope, terms used in functions. They start questioning each other about the terms used in chapter. Help them to find answers of following questions

Question. A variable created inside a function body
(a) Local variable
(b) Universal variable
(c) Global variable

Answer

A

Question. A name inside the parentheses of a function header that can receive a value?
(a) Formal argument
(b) Actual argument
(c) Global argument

Answer

A

Question. A name defined outside of all function definitions
(a) Formal argument
(b) Actual argument
(c) Global variable

Answer

C

Python Fundamentals Class 11 Computer Science Important Questions

Related Posts

error: Content is protected !!