0% found this document useful (0 votes)
16 views14 pages

STD Xii Holiday Practice Questions

The document contains a series of true or false questions and assertions regarding Python programming concepts, including language characteristics, operators, data types, and error handling. It also includes multiple-choice questions about Python syntax and features. Overall, it serves as a practice resource for understanding Python fundamentals.

Uploaded by

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

STD Xii Holiday Practice Questions

The document contains a series of true or false questions and assertions regarding Python programming concepts, including language characteristics, operators, data types, and error handling. It also includes multiple-choice questions about Python syntax and features. Overall, it serves as a practice resource for understanding Python fundamentals.

Uploaded by

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

1

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

A : Incorrect Output and a new variable is created by the same name in


R: There is a syntax error memory.
10. A: In Python comments are interpreted and are 18. A:To do arithmetic python uses arithmetic
shown on the output screen. (+,*,//,**, -, /,%)
R: Single line comments in python starts with # R:Each of these operators is a binary operator
character 19. A: The relational operator determine the
11. A: Python uses the concept of L-value andR- relation among different operand
value, that is derived from the typical mode of R:It returns the boolean value
evaluation on the left and right side of an 20. A: not has a lower priority than non-Boolean
assignment statement operators
R: name = “Raj” R: So not a==b is interpreted as not(a==b)
In the above code the value „Raj‟ is fetched 21. A: The ** operators is evaluated from right to
(Rvalue) and stored in the variable named – name left
(L value) R:All operators are left associative
12. A : Age=18 print(age) 22. A: for the given expression
R : Variables are case sensitive v1='1'
13. A:>>> print(type((3 + 33)<-(-4 - 44))) v2= 1
R : As output is True which is a boolean value v3= v1==v2 #value of v3 is False
14. num1=input("enter a number") R: Integer value cannot be compared with string
print(num1+2) value.
A: The above code will give error message when 23. A: following given expression will result into
executed. Type Error
R:input() returns a string datatype. We cannot add str1="ABC"
String datatype with a numeric datatype. So, v1=[2]
performing arithmetic operation on it will result in str3=str1*v1
error. R: operator „*‟ cannot be applied on string
15. var1=10 24. A:int(„A‟) The above statement will result into
var1="hello" error
A: The above code is invalid. We cannot assign a R: “A” is not recognised by Python
data of different data type to an existing variable. 25. A: a=9, b=int(9.2) Both a and b have same
R: Python supports implicit type casting. So it is value
possible to assign a data of different data type to R:b is converted to integer explicitly
an existing variable. 26. A: In an expression, associativity is the solution
16. A: You will get an error if you use double to the order of evaluation of those operators which
quotes inside a string that is surrounded by double clashes due to same precedence.
quotes: R: Operators in an expression may have equal
txt = "We are the so-called "Vikings" from the precedence due to which the order of evaluation
north." cannot be decided just by precedence.
R: To fix this problem, use the escape character \": 27. A:SyntaxError: Missing parentheses in call to
17. A: Variables whose values can be changed after “print”.
they are created and assigned are called immutable. R:SyntaxError: It is raised when there is an error in
R: When an attempt is made to update the value of the syntax of the Python code.
an immutable variable, the old variable is destroyed 28. A: NameError: name 'X' is not defined
3

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

(c) ZeroDivisionError (d) TypeError else:


69. It is raised when a local or global variable name print(“no output”)
is not defined. (a) ok (b) okok (c) no output (d) none of above
(a) IndexError (b) IndentationError 80. identify one possible output of this code out of
(c) ZeroDivisionError (d) NameError the following options:
70. It is raised due to incorrect indentation in the from random import*
program code. Low=randint(2,3)
(a) IndexError (b) IndentationError High=randrange(5,7)
(c) ZeroDivisionError (d) NameError for N in range(Low,High):
71. It is raised when an operator is supplied with a print(N,end=' ')
value of incorrect data type. (a) 3 4 5 (b) 2 3 (c) 4 5 (d) 3 4 5 6
(a) IndexError (b) TypeError 81. Given the nested if-else below, what will be the
(c) ZeroDivisionError (d) NameError value x when the source code executed
72. It is raised when the result of a calculation successfully:
exceeds the maximum limit for numeric data type.
(a) OverFlowError (b) TypeError
(c) ZeroDivisionError (d) NameError x=0
73. IndentationError is a type of: a=5
(a) SyntaxError (b) Logical Error b=5
(c) Runtime Error (d) Other if a>0:
74. Which of following is not a decision-making if b<0:
statement? x=x+5
(a) if-elif statement (b) for statement elif a>5:
(c) if -else statement (d) if statement x=x+4
75. In a Python program, a control structure: else:
(a) Defines program-specific data structures x=x+3
(b) Directs the order of execution of the statements else:
in the program x=x+2
(c) Dictates what happens before the program starts print (x)
and after it terminates 82. Which of the following is False regarding loops
(d) None of the above in Python?
76. Which one of the following is a valid Python if (a) Loops are used to perform certain tasks
statement? repeatedly.
(a) if a>=9: (b) if (a>=9) (c) if (a=>9) (d) if a>=9 (b) while loop is used when multiple statements are
77. if 4+5==10: to executed repeatedly until the given condition
print("TRUE") becomes true.
else: (c) while loop is used when multiple statements are
print("false") to executed repeatedly until the given condition
print ("True") becomes false
(a) False (b) True (c) false (d) None of these (d) for loop can be used to iterate through the
78. Predict the output of the following code: elements of lists.
X=3 83. The for loop in Python is an _____________
if x>2 or x<5 and x==6: (a) Entry Controlled Loop (b) Exit Controlled Loop
print("ok") (c) Both of the above (d) None of the above
8

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

(a) Value of x (b) Datatype of x 6. Evaluate the following: >>>


(c) Size of x (d) Memory address of x print(15.0/4+(8*3.0))
98. What will the following expression be evaluated 7. Sona has written the following code to check
to in Python? >>> print((4.00/(2.0+2.0))) whether number is divisible by 3. She could not run
a)Error b)1.0 c)1.00 d)1 the code successfully. Rewrite the code and
99. Which of the following datatype in python is underline each correction done in the code.
used to represent any real number : x=10
(a) int (b) complex (c) float (d) bool for I range in (a)
100 >>> print( ( - 33 // 13) * (35 % -2)* 15/3) if i%3=0:
(a) 10.0 (b) -15.0 (c) 15.0 (d) -10.0 print(I)
101 Which of the following statement(s) would else
give an error after executing the following code? pass
x= int("Enter the Value of x:")) #Statement 1 8. Rewrite the following code in Python after
for y in range[0,21]: #Statement 2 removing all syntax error(s). Underline each
if x==y: #Statement 3 correction done in the code.
print (x+y) #Statement 4 Value=30
else: #Statement 5 for VAL in range(0,Value)
print (x-y) # Statement 6 if val%4==0:
(a) Statement 4 (b) Statement 5 print (VAL*4)
(c) Statement 4 & 6 (d) Statement 1 & 2 Elseif val%5==0:
2 – MARKS print (VAL+3)
1. Evaluate the following expression: else
False and bool(15/5*10/2+1) print(VAL+10)
2. If given A=2,B=1,C=3, What will be the output 9. Mona has written a code to input a positive
of following expressions: integer and display all its even factors in descending
(i) print((A>B) and (B>C) or(C>A)) order. Her code is having errors. Rewrite the correct
(ii) print(A**B**C) code and underline
3. Write the output of the code given below: the corrections made.
p=10 n=input("Enter a positive integer: ")
q=20 for i in range(n):
p*=q//3 if i%2:
p=q**2 if n%i==0:
q+=p print(i,end=' ')
print(p,q) 10. Find error in the following code(if any) and
4. Evaluate the following expressions: correct code by rewriting code and underline the
(a) 5 // 10 * 9 % 3 ** 8 + 8 – 4 correction;‐
(b) 65 > 55 or not 8 < 5 and 0 != 55 x= int(“Enter value of x:”)
5. Fill in the blanks to execute loop from 10 to 100 for in range [0,10]:
and 10 to 1 if x=y
(i)for i in range(_______ ): print( x + y)
print(i) else:
(ii)for i in range( _______): print( x‐y)
print(i) 11. Mithilesh has written a code to input a number
and evaluate its factorial and then finallyprint the
10

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

sum += x # Add every number from 1 to i


print(i, sum) # print the result
a) What is the error you have identified in this 27. Predict the output of the following:
code? for i in range(1, 15, 2):
b) Rewrite the code by underlining the correction/s. temp = i
20. Evaluate the following expressions: if i%3==0:
a) 6+7*4+2**3//5-8 b) 8<=20 and 11 temp = i+1
21. Write the difference between break and elif i%5==0:
continue. continue
22. Predict the output of the following: elif i==11:
X=3 break
Y=5 print(temp, end='$')
Z = -2
X *= Y + Z 28. Predict the output of the following:
Y -= X * 2 + Y P,S=1,0
Z += X + Y for X in range(-5,15,5):
print(X, Y, Z) P*=X
23. Predict the output of the following code: S+=X
X=3 if S==0:
Y=2 break
Z = -5 else:
X -= Y + Z print(P, "#", S)
Y //= X - Z
Z *= X + Y 29. Predict the output of the following:
print(X, Y, Z) for x in range(1, 4):
24. Predict the output of the following: for y in range(2, 5):
M, N, O = 3, 8, 12 if x * y > 6:
N, O, M = O+2, M*3, N-5. break
print(N,O,M) print(x*y, end="#")
25. V, W, X = 20, 15, 10
W, V, X = X-2, V+3, W*2. 30. N=5
print(V,X,W) C=1
26. Predict the output of the following: while (C<8):
a=None if(C==3 or C==5):
b=None C+=1
x=4 continue
for i in range(2,x//2): print(C,'*',N,'=',C*N)
if x%i==0: C+=1
if a is None:
a=i
else:
b=i
break
print(a,b)
12

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. What is an argument? Give an example.


Q4. What is the output of the program given below?

Q10. What is the difference between parameter and


argument?
Q11. What is the significance of having functions in
a program?
Q5. What will be the output of the following code:
Q12. What is the difference between local variable
and global variable? Also give a suitable Python
code
to illustrate both.
Short Questions (3 Marks)
Q1. Consider the following function that takes two
positive integer parameters a and b. Answer the
following questions based on the code below:

Q6. Is return statement optional? Compare and


comment on the following two return statements:
(i) return
(ii) return val
Q7. Divyansh, a python programmer, is working on
a project which requires him to define a function
with name CalculateInterest(). He defines it as:
def CalculateInterest(Principal,Rate=.06, Time): # (a) What will be printed by the fuction call
Code funct1(24,2)?
But this code is not working, Can you help (b) What will be printed by the fuction call
funct1(84,2)?
Divyansh to identify the error in the above function
(c) State in one line what funct1()is trying to
and with the solution? calculate.
14

Q2. Write a user defined function to print the odd


numbers from a given list passed as an argument.
Sample list: [1,2,3,4,5,6,,7,8,9,10]
Expected Result: [1,3,5,7,9]

Q3. Which line in the given code(s) will not work and
why?

Q4. Write a python function showlarge() that accepts


a string as parameter and prints the words whose
length is more than 4 characters. On the basis of the above code, choose the right
Eg: if the given string is “My life is for serving my statement which will be executed when different
Country” inputs for pay and location are given
The output should be serving
Country (i) Input: location = “Chennai”, pay = 50000

Q5. Write a function Interchange (num) in Python, a. Statement 1 b. Statement 2


which accepts a list num of integers, and interchanges b. c. Statement 3 d. Statement 4
the adjacent elements of the list and print the modified
list as shown below: (ii) Input: location = “Surat” ,pay = 50000
(Number of elements in the list is assumed as even)
Original List: num = [5,7,9,11,13,15] a. Statement 2 b. Statement 4
After Rearrangement num = [7,5,11,9,15,13] c. Statement 5 d. Statement 6
(iii) Input- location = “Any Other City”, pay = 1
Q6. Write a function INDEX_LIST(L), where L is the
list of elements passed as argument to the function. a Statement 1 b. Statement 2
The function returns another list named ‘indexList’ c. Statement 4 d. Statement 6
that stores the indices of all Non-Zero Elements of L.
For example: (iv) Input location = “Delhi”, pay = 500000
If L contains [12, 4, 0, 11,0, 56] a. Statement 6 b. Statement 5
The indexList will have - [0,1,3,5] c. Statement 4 d. Statement 3

Q1. Krishnav is looking for his dream job but has


some restrictions. He loves Delhi and would take a
job there if he is paid over Rs.40,000 a month. He
hates Chennai and demands at least Rs. 1,00,000 to
work there. In any another location he is willing to
work for Rs. 60,000 a month. The following code
shows his basic strategy for evaluating a job offer.

You might also like