STD Xii Holiday Practice Questions
STD Xii Holiday Practice Questions
HOLIDAY PRACTICE QUESTIONS 24. print() always inserts a newline after each
STATE TRUE OR FALSE output.
1. Python is a low level language. 25. >>> 2*4+36/2-9
2. Python is a free source language. In the above expression 36/2 will be evaluated first
3. Python converts low level language to high level by python.
language. 26. When syntax error is encountered, Python
4. Python is a compiler. displays the name of the error and a small
5. Python is case sensitive language. description about the error.
6. Python was named after famous BBC comedy 27. "In Python, data type of a variable depends on
show namely Monty Python’s Flying Circus. its value"
7. Python is not a Cross-platform Language. 28. “Python identifiers are dynamically typed.”
8. All identifiers in Python are in lower case. 29. (i) -88.0 is the output of the
9.(i) An identifier is a user defined name given to a print(3-10**2+99/11)
variable or a constant in a program. (ii) range( ) is also a module function
9.(ii) Python does not allows same variable to hold 30. “Comments in Python begin with a "$"
different data literals / data types. symbol.”
10. Operators with the same precedence are ASSERTION & REASON
evaluated in right to left manner. 1. A:It is interpreted language.
11. Interactive mode is used when a user wants to R: Python programs are executed by an
run a single line or one block of code. interpreter.
12. Script mode is used when the user is working 2. A: Python is portable and platform independent.
with more than one single code or a block of code. R:Python program can run on various operating
13. In Python, a variable may be assigned a value of systems and hardware platforms.
one type, and then later assigned a value of a 3. A: Python is case-sensitive.
different type. R:Python does not use indentation for blocks and
14. In Python, a variable must be declared before it nested blocks.
is assigned a value. 4. A: Python program is executed line by line.
15. Variable names can be of any length. R: Python is compiled language.
16. the complement operator inverts the value of 5. A: Python is an object oriented language
each bit of the operand R: Python is a cross platform language
17. print(int(6>7-6-7*4) ) will print boolean value. 6. A: Python is case-sensitive.
18. Logical operator not has highest precedence R: NUMBER and number are not same in
among all the logical operators. Python
19. “is” is a membership operator in python. 7. A: Python is a high-level object- oriented
20. Following code will produce True as output: programming language.
x=10>5>1 and -3<-2<-1 R: It can run on different platforms like
print(x) Windows, Linux, Unix, and Macintosh.
21. The value of expression 8. A: An identifier cannot have the same name as of
3/5*(7-2) and 3/(5*(7-2)) issame. a keyword.
22. The expression 4**3**2 is evaluated as R: Python interpreter will not be able to
(4**3)**2 differentiate Between a keyword and an identifier
23. () have higher precedence that any other having the same name as of a keyword.
operator. 9. >>>print('Good'+' Morning')
#Output :Goodmorning
2
R:NameError: It is raised when the requested 1 + 3 + 5…….n. Ravi used the range function in for
module definition is not found. loop as follows :range(1,n+1,2) # 3 parameters
29. A:ZeroDivisionError: division by zero R: In range function first parameter is start
R:ZeroDivisionError: It is raised when the value, second parameter is stop value & the third
denominator in a division operation is zero. parameter is step value.
30. A: TypeError: can only concatenate str (not 38. x = 0
"int") to str for i in range(3,9,3):
R: TypeError: It is raised when an operator is x = x * 10 + i
supplied with a value of incorrect data type. print(x)
31. A: An example of an infinite loop is : while(1): A: The output of the above code will be 9.
R: A loop that continues repeating without a R:The loop will run for 2 times.
terminating (ending) condition is an infinite loop. 39. for i in range(1, 6):
32. A: The statements within the body of for loop for j in range(1, i):
are executed till the range of values is exhausted. print("*", end=" ")
R: for loop cannot be nested. print()
33. Analyse the following code: A: In a nested loop, the inner loop must terminate
for i in range(1,4): before the outer loop.
for j in range (1,i+1): R:The above program will throw an error.
print(j,end=‟ ‟) 40. A: break statement terminates the loop.
print() R: The else clause of a Python loop executes
A: output is when the loop continues normally.
1 41. A:break statement appears in a nested loop.
12 R:If the break statement is inside the inner loop
123 then it will not terminate the inner loop then it will
R: Here, range function will generate value 1,2,3 in terminate the outer loop only
the outer loop and the inner loop will run for each 42. A: break statement terminates the loop it lies
value of “i” used in outer loop. within.
34. A: Python provides two looping constructs for R: continue statement forces the next iteration of
and while. The for is a counting loop and while is a the loop to take place,
conditional loop. skipping any code in between.
R: The while is a conditional loop as we check the 43. A: The math.pow(2,4)gives the output: 16.0
condition first, if it is satisfied then only we can get R: The math.pow() method receives two float
inside the while. In case of for it depends upon the arguments, raise the first to the second and return
counting statement of index. the result.
35. A: for loop in Python makes the loop easy to OBJECTIVE TYPE QUESTIONS (MCQ)
calculate factorial of a number 1. Python uses ____ to convert its instructions into
R: While loop is an indefinite iteration that is used machine language.
when a loop repeats unknown number of times and (a)Interpreter (b)Compiler
end when some condition is met. (c)Both of the above (d)None of the above
36. A: range(0,5) will produce list as [0,1,2,3,4] 2. Who developed the Python language?
R:These are the numbers in arithmetic (a) Zim Den (b)Wick van Rossum
progression(a.p.) that begins with lower limit 0 and (c)Guido Van Rossum (d)NieneStom
goes up till upper limit -1. 3. IDLE stands for __________
37. A: To print the sum of following series (a) Integrated Development Learning
4
(b) Integrated Development Learning Environment (a) sub%marks (b) age (c) _subname_ (d) subject1
(c) Intelligent Development Learning Environment 15. Which of the following expressions is an
(d) None of the above example of type casting?
4. Python interpreter executes (a) 4.0+float(6) (b) 5.3+6.3
……………………….statement (Command) at a (c) 5.0+3 (d) None of these
time. 16. Which of the following is an invalid identifier?
(a) Two (b) Three (c) One (d) All command (a) CS_class_XII (b) csclass12
5. Which of the following is not the feature of (c) _csclass12 (d) 12CS
Python language? 17. The input() function always returns a value of
(a) Python is proprietary software. ……..type.
(b )Python is not case-sensitive. a) Integer b) float c) string d) Complex
(c) Python uses brackets for blocks and nested 18. To include non-graphic characters in python,
blocks. which of the following is used?
(d) All of the above a. Special Literals b. Boolean Literals
6. By default, the Python scripts are saved c. Escape Character Sequence d. Special Literal –
with_____extension. None
(a) .pyp (b).pys (c).py (d)None of the above 19. Which of the following cannot be a variable
7. What is the maximum possible length of an name?
identifier in python? (a) _init_ (b) in (c) it (d) on
(a) 16 (b) 32 (c) 64 (d) None of these 20. Which is valid keyword?
8. >>> print("I" + "am" + "in" + "school") display (a) Int (b) WHILE (c) While (d) if
(a) I am in school (b)I Am In School 21. Predict the output of the following:
(c)Iaminschool (d)iaminschool (i) >>>print(10 or 40) (ii) >>> print(22.0//5)
9. Which of the following statement is correct 22. Which of the following is an invalid operator in
syntactically? Python?
(a) print(“Hello” , sep == „@‟ , end =' ') (a) - (b) //= (c) in (d) =%
(b)print(“Hello” , sep = „@‟ , end = ' ') 23. Which of the following operators is the correct
(c)Print(“Hello” , sep = „@‟ , end = ' ') option for power(a,b)?
(d)print(“Hello” , sep = „@‟ , end = ' ' (a) a^b (b) a **b (c) a ^^b (d) a^*b
10. Which of the following is not a keyword in 24. Which of the characters is used in python to
python? make a single line comment?
(a) eval (b) assert (c) nonlocal (d) pass (a)/ (b) // (c) # (d)!
11. Which of the following is not a valid 25. Which of the following is not a core data type in
declaration? python?
(a) S=12 (b) V="J" (c) F=32.4 (d) H=0254 (a)List (b) Dictionary (c) Tuple (d) Class
12. Evaluate the following expression: 26. Which of the following has the highest
>>> not True or not False and False precedence in python?
(a) True (b) False (c) None (d) Will generate an (a)Exponential (b) Addition
Error (c) Parenthesis (d) Division
13. All keywords in python except TRUE and 27. What is math.factorial(4.0)?
FALSE are in ____? (a) 20 (b) 24 (c) 16 (d) 64
(a) Lower case (b) Upper case 28. Identify the invalid variable name from the
(c) Capitalized (d) None of the above following.
14. Find the invalid identifier from the following Adhar@Number, none, 70outofseventy, mutable
5
29. Which of the following belongs to complex (a) True (b) False (c) None (d) NULL
datatype 42. >>> 16 // (4 + 2) * 5 + 2**3 * 4
(a) -12+2k (b) 4.0 (c) 3+4J (d) -2.05I (a) 42 (b) 46 (c) 18 (d) 32
30. None is a special data type with a single value. 43. Evaluate the following expression:
It is used to signify the absence of value in a True and False or Not True
situation (a) True (b) False (c) NONE (d) NULL
(a) TRUE (b) FALSE (c) NONE (d) NULL 44. The below given expression will evaluate to
31. If x=3.123, then int(x) will give ? 22//5+2**2**3%5
(a) 3.1 (b) 0 (c) 1 (d) 3 (a)5 (b) 10 (c) 15 (d) 20
32. To execute the following code in Python, Which 45. Which of the following is not a valid identifier
module need to be imported? name in Python?
>>>print(_______.mean([1,2,3]) a) First_Name b) _Area c) 2nd_num d) While
33. Find the invalid identifier from the following 46. Evaluate the following Python expression
(a) Marks@12 (b) string_12 (c)_bonus print(12*(3%4)//2+6)
(d)First_Name (a)12 (b)24 (c) 10 (d) 14
34. Find the invalid identifier from the following 47. Give the output of the following code:
(a) KS_Jpr (b) false (c) 3rdPlace (d) _rank >>>import math
35. Find the valid identifier from the following: >>>math.ceil(1.03)+math.floor(1.03)
(a) Tot$balance (b) TRUE (c) 4thdata (d) break a) 3 b) -3.0 c) 3.0 d) None of the above
36. Which one of the following is False regarding 48. >>>5 == True and not 0 or False
data types in Python? (a) True (b) False (c) NONE (d) NULL
(a) In python, explicit data type conversion is 49. Predict the output of the following:
possible from math import*
(b) Mutable data types are those that can be A=5.6
changed. print(floor(A),ceil(A))
(c) Immutable data types are those that cannot (a) 5 6 (b) 6 5 (c) -5 -6 (d) -6 -5
Be changed. 50. Predict the output of the following code:
(d) None of the above import math
37. Which statement will give the output as : True print(math.fabs-10))
from the following : (a) 1 (b) -10 (c) -10.0 (d) 10
a) >>>not -5 b) >>>not 5 c) >>>not 0 d) >>>not(5- 51. Which of the following function is used to know
1) the data type of a variable in Python?
38. Evaluate the following expression: (a) datatype() (b) typeof() (c) type() (d) vartype()
1+(2-3)*4**5//6 52. Identify the invalid Python statement from the
(a) -171 (b) 172 (c) -170 (d) 170 following.
39. The correct output of the given expression is: (a) _b=1 (b) b1= 1 (c) b_=1 (d) 1 = _b
True and not False or False 53. A=100
(a) False (b) True (c) None (d) Null B=A
40. What will the following expression be evaluated Following the execution of above statements,
to in Python? python has Created how many objects and how
print(6*3 / 4**2//5-8) many references?
(a) -10 (b) 8.0 (c) 10.0 (d) -8.0 (a) One object Two reference (b) One object One
41. Evaluate the following expressions: reference
>>>(not True) and False or True (c) Two object Two reference (d) Two object One
6
reference v1='1'
54. What is the output of the following code? v2= 1
a,b=8/4/2, 8/(4/2) v3=v1==v2
print(a,b) (a) Type Error (b) Value Error
(a) Syntax error (b) 1.0,4.0 (c) 4.0,4.0 (d) 4,4 (c)True will be assigned to v3 (d)False will be
55. Predict output for following code assigned to v3
v1= True (a) 26 11 (b) 25 11
v2=1 (c) 30 12 (d) 26 10
print(v1==v2, v1 is v2) 62. Which of the following operators has highest
(a) True False (b) False True precedence:
(c) True True (d) False False +,-,/,*,%,<<,>>,( ),**
56. Find output for following given program (a) ** (b) ( ) (c) % (d)-
a=10 63. Which of the following results in an error?
b=20 (a) float(„12‟) (b) int(„12‟)
c=1 (c) float(‟12.5‟) (d) int(„12.5‟)
print(a !=b and not c) 64. Which of the following is an invalid statement?
(a) 10 (b) 20 (c) True (d) False (a) xyz=1,000,000 (b) x y z = 100 200 300
57. Find output of following given program : (c) x,y,z=100,200,300 (d) x=y=z=1,000,000
str1_ = "Aeiou" 65. Which of the following defines SyntaxError?
str2_ = "Machine learning has no alternative" (a) It is raised when the file specified in a program
for i in str1_: statement cannot be opened.
if i not in str2_: (b) It is raised when there is an error in the syntax
print(i,end='') of the Python code.
(a) Au (b) ou (c) Syntax Error (d) value Error (c) It is raised when the requested module definition
58. Find output for following given code is not found.
a=12 (d) It is raised due to incorrect indentation in the
print(not(a>=0 and a<=10)) program code.
(a) True (b) False (c) 0 (d)1 66. Which of the following defines ValueError?
59. What will be value of diff ? (a) It is raised when the file specified in a program
c1='A' statement cannot be opened.
c2='a' (b) It is raised when there is an error in the syntax
diff= ord(c1)-ord(c2) of the Python code.
print(diff) (c) It is raised when a built-in method or operation
(a) Error : unsupported operator „-‟ (b) 32 receives an argument that has the right data type but
(c)-32 (d)0 Mismatched or inappropriate values.
60. What will be the output after the following (d) It is raised due to incorrect indentation in the
statements? program code.
x = 27 67. It is raised when the denominator in a division
y=9 operation is zero.
while x < 30 and y < 15: (a) IndexError (b) IndentationError
x=x+1 c) ZeroDivisionError (d) TypeError
y=y+1 68. It is raised when the index or subscript in a
print(x,y) sequence is out of range.
61. What output following program will produce (a) IndexError (b) IndentationError
7
84. What abandons the current iteration of the loop? 89. Examine the given Python program and select
(a) continue (b) break (c) stop (d) infinite the purpose of the program from the following
85. The following code contains an infinite loop. options:
Which is the best explanation for why the loop does N=int(input("Enter the number"))
not terminate? for i in range(2,N):
n = 10 if (N%i==0):
answer = 1 print(i)
while n > 0: (a) To display the proper factors(excluding 1 and
answer = answer + n the number N itself)
n=n+1 (b) To check whether N is a prime or Not
print(answer) (c) To calculate the sum of factors of N
(a) n starts at 10 and is incremented by 1 each time (d) To display all prime factors of the Number N.
through the loop, so it will always be positive. 90. If A=random.randint(B,C) assigns a random
(b) Answer starts at 1 and is incremented by n each value between 1 and 6(both inclusive) to the
time, so it will always be positive. identifier A, what should be the values of B and C,
(c) You cannot compare n to 0 in the while loop. if all required modules have already been imported?
You must Compare it to another variable. (a) B=0, C=6 (b) B=0,C=7 (c) B=1,C=7 (d)
(d) In the while loop body, we must set n to False, B=1,C=6
and 91. Predict the output of the following code:
(a) 0 (b) 4 (c) 2 (d) 3 import statistics as S
This Code does not do that. D=[4,4,1,2,4]
86. What will the following code print? print(S.mean(D),S.mode(D))
for i in range(1,4): (a) 1 4 (b) 4 1 (c) 3 4 (d) 4 3
for j in range(1,4): 92. The continue statement is used:
print(i, j, end=' ') (a) To pass the control to the next iterative
(a) 1 1 2 2 3 3 statement
(b) 1 2 3 1 2 3 1 2 3 (b) To come out from the iteration
(c) 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 (c) To break the execution and passes the control to
(d) 1 1 2 1 3 1 2 1 2 2 2 3 3 1 3 2 3 3 else statement
87. When does the else statement written after loop (d) To terminate the loop
executes? 93. Common types of exception in python are:
(a) When break statement is executed in the loop (a) Syntax Error (b) Zero division error
(b) When loop condition becomes false (c) (a) and (b) (d) None of these
(c) Else statement is always executed 94. Which of the following is an incorrect logical
(d) None of the above operator in python?
88. What will be the output of the following Python (a) not (b) in (c) or (d) and
code? 95. Which of the following is not a function/method
for x in range(1, 4): of the random module in python?
for y in range(2, 5): (a) randfloat( ) (b) randint( )
if x * y > 6: (c) random( ) (d) randrange( )
break 96. Which of the following symbols are used for
print(x*y, end=“#”) comments in Python?
(a) 2#3#4#4#6#8#6#9#12# (b) 2#3#4#5#4#6#6# (a) // (b) & (c) /**/ (d) #
(c) 2#3#4#4#6#6# (d) 2#3#4#6 97. print (id(x)) will print_______.
9
result in the format : “The factorial of the 15. (i)Find the output generated by the following
<number> is <factorial value>” His codeis having code:
errors. Rewrite the correct code a=5
and underline the corrections made. b=10
f=0 a+=a+b
num = input("Enter a number:") b*=a+b
n = num print(a,b)
while num> 1: (ii)Answer the following questions from the
f = f * num following code:
num -= 1 num_list=["One","Two","Three","Four"]
else: for c in num_list:
print("The factorial of : ", n , "is" , f) print(c)
12. Rewrite the following code after removing the (i) What will be the output of the above code?
syntactical error(if any).Underline each correction: (ii) How many times the loop executed?
X=input("Enter a Number") 16. Predict the output of the following code:
If x % 2 =0: num=123
for i range (2*x): f=0
print i s=0
loop else: while(num > 3):
print "#" rem = num % 100
13. What possible outputs are expected to be if(rem % 2 != 0):
displayed on screen at the time of execution of the f += rem
program from the following code? Also specify the else:
maximum value that can be assigned to each of the s+=rem
variables L and U. num /=100
import random print(f-s)
Arr=[10,30,40,50,70,90,100] 17. Evaluate the following expressions:
L=random.randrange(1,3) a) 7*3+4**2//5-8 b) 7>5 and 8>20 or not 12>4
U=random.randrange(3,6) 18. Predict the output of the following:
for i in range(L,U+1): for i in range(4):
print(Arr[i],"@",end="") if i==4:
break
(i) 40 @50 @ (ii) 10 @50 @70 @90 @ else:
(iii) 40 @50 @70 @90 @ (iv) 40 @100 @ print(i)
14. Rewrite the following Python program after else:
removing all the syntactical errors (if any), print("Welcome")
underlining each correction: 19. Anu wrote the code that, prints the sum of
x=input(“Enter a number”) numbers between 1 and the number, for each
if x % 2=0: number till 10.She could not get proper output.
print x, “is even” i=1
else if x<0: while (i <= 10): # For every number i from 1 to
print x, “should be positive” 10
else; sum = 0 # Set sum to 0
print x “is odd” for x in range(1,i+1):
11
FUNCTIONS
8. What is the order of resolving scope of a name in
Multiple Choice Questions (1 Mark)
a python program?
(L: Local namespace, E: Enclosing namespace, B:
1. What is the default return value for a function
Built-In namespace, G: Global namespace)
that does not return any value explicitly?
(a) BGEL (b) LEGB (c) GEBL (d) LBEG
(a) None (b) int (c) double (d) null
9. Assertion (A):- If the arguments in a function call
2. Which of the following items are present in the
statement match the number and order of arguments
function header?
as defined in the function definition, such
(a) Function name only (b) Parameter list only
arguments are called positional arguments.
(c) Both function name and parameter list (d) return
value
Reasoning (R):- During a function call, the
argument list first contains default argument(s)
3. Which of the following keyword marks the
followed by positional argument(s).
beginning of the function block?
(a) Both A and R are true and R is the correct
(a) func (b) define (c) def (d) function
explanation for A
(b) Both A and R are true and R is not the correct
4. Pick one of the following statements to correctly
explanation for A
complete the function body in the given code
snippet. (c) A is True but R is False
def f(number): (d) A is false but R is True
# Missing function body print (f(5))
(a) return “number” (b) print(number) (c) 10. The ......................... refers to the order in which
print(“number”) (d) return number statements are executed during a program run.
(b) (a) Token (b) Flow of execution
5. Which of the following function header is (c) Iteration (d) All of the above
correct?
(a) def f(a=1,b): (b) def f(a=1,b,c=2): 11. Choose the correct option:
(c) def f(a=1, b=1, c=2): (d) def f(a=1,b=1,c=2,d); Statement1: Local Variables are accessible only
within a function or block in which it is declared.
6. Which of the following statements is not true for Statement2: Global variables are accessible in the
parameter passing to functions? whole program.
(a) You can pass positional arguments in any order. (a) Statement1 is correct but Statement2 is incorrect
(b) You can pass keyword arguments in any order. (b) Statement2 is correct but Statement1 is incorrect
(c) You can call a function with positional and (c) Both Statements are Correct
keyword arguments. (d) Both Statements are incorrect
(d) Positional arguments must be before keyword
arguments in a function call 12. The ............................ of a variable is the area of
the program where it may be referenced
7. A variable defined outside all the functions a) external b) global c) scope d) local
referred to as……….. Short Questions (2 Marks)
(a) A static variable (b)A global variable Q1. What do you mean by a function? How is it
(c) A local variable (d) An automatic variable useful?
13
Q2. Observe the following Python code very Q8. Write a function that takes a positive integer
carefully and rewrite it after removing all and returns the one’s position digit of the integer.
syntactical errors with each correction underlined.
Q9. Anita has written a code to input a number and
check whether it is prime or not. His code is having
errors. Rewrite the correct code and underline the
corrections made.
Q3. Which line in the given code(s) will not work and
why?