0% found this document useful (0 votes)
7 views41 pages

Unit-1 Python Revision Tour Question Bank

Uploaded by

dhanvinbellam7
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)
7 views41 pages

Unit-1 Python Revision Tour Question Bank

Uploaded by

dhanvinbellam7
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
You are on page 1/ 41

1 Revision Tour SECTION : A

n
ha
1. What is python?
Ans. Python is an interpreted, high-level, general-purpose programming language, which was created by Guido van

as
Rossum. It was first released in 1991. It is used in many applications like Software Development, Web Development,
System Scripting, Mathematics, etc.
features of Python

ak
• Easy to use: due to simple syntax, it is very easy to implement.
• Interpreted Language: In python, every code is executed line by line.
• Cross-platform Language: can run on any platform Windows, Linux, Macintosh, Raspberry Pi, etc.

Pr
• Expressive Language: It supports a wide range of library.
• Free & Open Source: It can be downloaded free of cost.
disadvantages
Lesser Libraries: As compared to other programming languages like c++, java, .Net, etc. it has a lesser number
rs

of libraries.
• Slow Language: Being an interpreted language, the code is executed slowly.
e
• Weak on Type-Binding: A variable that is initially declared int can be changed to string at any point in the
program without any typecasting.
th

2. What is variable?
Ans. A variable is a named location used to store data in the memory. For example, in the following statement a
variable ‘n’ is created and assigned the value 10 to n.
ro

n=10
3. How can multiple values be assigned to multiple variables and same value to different variables.
lB

Ans. Assigning multiple values to multiple variables:


a,b,c=10,20,”hello”
Assign the same value to multiple variables at once:
x=y=z=50
a

4. Write code to create a variable num and assign 100 value to num.
oy

Ans. num=100

1. tOKens
5. Define token in python.
G

Ans. Token: The smallest individual unit in a program is known as a token. There are five types of tokens allowed
in Python. They are :
• Keywords • Identifiers • Literals • Operators • Punctuators

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 1
(i) Keywords
Keywords are the reserved words in Python. We cannot use a keyword as a variable name, function name or any other
identifier. They are used to define the syntax and structure of the Python language. In Python, keywords are case sensitive.
False class from or
None continue global pass

n
True def if raise
and del import return

ha
as elif in try
assert else is while
async except lambda with

as
await finally nonlocal yield
break for not

ak
(ii) Identifier
An identifier is a name given to entities like class, functions, variables etc.
Rules for writing identifiers

Pr
• Identifier must always start with either a letter or an underscore (_). For example: _str, str, num, _num are all
valid name for the variables.
• Identifiers cannot start with a number. For example, 9num is not a valid variable name.
rs
• The identifier cannot have special characters such as %, $, #.- etc, they can only have alphanumeric characters
and underscore (A to Z, a to z, 0-9 or _ ).
• An identifier cannot contain space.
e
• Identifier is case sensitive in Python which means num and NUM are two different variables in python.
• Keywords cannot be used as identifier.
th

6. Out of the following, find those identifiers, which cannot be used for naming Variable or Functions in a Python
program: 2 [OD 16]
ro

Total*Tax, While, class, switch, 3rdRow, finally, Column31, _Total


Ans. Total*Tax, class, 3rdRow, finally
7. Identify invalid variable names out of the following. State reason if invalid. [OD 16]
lB

(i) for (ii) –salary (iii) salary12 (iv) product


Ans. Invalid variable names : (i) for and (ii) -salary
Reason : (i) ‘for’ : is a keyword
(ii) ‘-salary’ : variable name cannot start with special character.
a

8. Identify invalid variable name(s) out of the following. State reason if invalid [comptt 16]
oy

(i) While (ii) 123salary (iii) Big (iv) Product


Ans. (ii) 123salary
9. Help Manish in identifying the incorrect variable name with justification from the following:
G

(i) unit@price (ii) fee (iii) userid (iv) avg marks [SP 18]
Ans. (i) unit@price; // Special symbols like „@‟ is not allowed in variable name
(iv) avg marks;// Spaces are not allowed in variable name

2 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
10. Identify the invalid variable names. State the reason if invalid. 1 [2018]
(i) Marks Unit (ii) Product_1 (iii) Sales123 (iv) 2Marks
Ans. Invalid variable names are :
(i) Marks Unit
Reason : Variable Name should not contain space

n
(iv) 2Marks
Reason : Variable Name should not start with digit

ha
11. Which of the following can be used as valid variable identifier(s) in Python? 2[d 17]
(i) total (ii) 7Salute (iii) Que$tion (iv) global
Ans. (i) total

as
12. Which of the following can be used as valid variable identifier(s) in Python? 2 [compt 17]
(i) elif (ii) BREAK (iii) in (iv) _Total
Ans. (ii) BREAK (iv) _Total

ak
13. Which of the following can be used as valid variable identifier(s) in Python? [OD 17]
(i) 4thSum (ii) Total (iii) Number# (iv) _Data
Ans. (ii) Total (iv) _Data
14. Which of the following is not a valid variable name in Python. Justify reason for it not being a valid name:

Pr
[comptt 2020]
(i) 5Radius (ii) Radius_ (iii) _Radius (iv) Radius
Ans. (i) 5Radius
Reason: variable name in Python cannot start with a digit
rs
15. Which of the following are keywords in Python?
(i) break (ii) check (iii) range (iv) while [comptt 2020]
e
Ans. (i) break (iii) range (iv) while
16. Out of the following, find those identifiers, which cannot be used for naming Variable or Functions in a Python
th

program: 2 [D 16]
_Cost, Price*Qty, float, Switch, Address One,
ro

Delete, Number12, do
Ans. Price*Qty, float, Address One
17. Find the correct identifiers out of the following, which can be used for naming variable, constants or functions
lB

in a python program:
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
Ans. While, Float, Amount2, _Counter
18. Find the correct identifiers out of the following, which can be used for naming Variable, Constants or Functions
a

in python program: [OD 2015]


For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
oy

Ans. For, INT, NeW, name1


19. Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in
a python program:
_Cost, Price*Qty, float, switch, Address One, Delete, Number12, do
G

Ans. Price*Qty
float
Address One
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 3
20. Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in
a python program:
Total*Tax, double, Case, My Name, NeW, switch, Column31, _Amount
Ans. Total*Tax
My Name

n
21. Find the invalid identifier from the following: 1[SP 21]
(i) MyName (ii) True (iii) 2ndName (iv) My_Name

ha
Ans. (i) True, (ii) 2ndName
22. Write the type of python keywords and user defined identifiers from the following:
(i) For (ii) Delete (iii) else (iv) Value
Ans. (i) For - user defined identifier (ii) Delete - user defined identifier

as
(iii) else - keyword (iv) Value - user defined identifier
23. Write the type of python keywords and user defined identifiers from the following :
(i) case (ii) _delete (iii) while (iv) 21stName

ak
Ans. (i) keyword (ii) identifier
(iii) keyword (iv) None
24. Write the type of python keywords and user defined identifiers from the following:

Pr
(i) in (ii) While (iii) and (iv) Num_2
Ans. (i) in - Keyword (ii) While - User defined Identifier
(iii) and - Keyword (iv) Num_2 - User defined Identifier
25. Write the type of python keywords and user defined identifiers from the following:
rs
(i) else (ii) Long (iii) break (iv) _count
Ans. (i) keyword (ii) Identifier (iii) keyword (iv) Identifier
e
26. Identify the valid keywords in Python from the following: [2] [comptt 2020]
(i) Queue (ii) False (iii) in (iv) Number
th

(v) global (vi) method (vii) import (viii) List


Ans. (ii) False (iii) in (v) global (vii) import
27. Write the type of tokens from the following: 1[SP 20]
ro

(i) if (ii) roll_no


Ans. (i) Keyword (ii) Identifier
lB

(iii) Literal
Literal is a raw data given in a variable. There are various types of literals
(a) Numeric literals: Three types of numeric literals available in python: integer, float and complex
Int literals Float literals Complex literals
a

a=123 x=3.14 z=4.13j


b=839 y= 2.85
oy

(b) String literals: A string literal is a sequence of characters surrounded by quotes. We can use both single, double,
or triple quotes for a string
a= “hello”
G

b= ‘12345’
(c) Boolean literals: A Boolean literal can have any of the two values: True or False
(d) Special literals: Python contains one special literal i.e. None

4 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
(e) Literal Collections: There are four different literal collections: List literals, Tuple literals, Dict literals, and Set
literals.
(i) List literals :: [5,6,7] (ii) Tuple literals :: (1,2,3)
(iii) Dict literals :: {‘x’:1} (iv) Set literals :: {8,9,10}

(iv) Punctuators

n
Most commonly used punctuators in Python are:
‘ “ # \ () {} [] @ , : . =

ha
(v) Python Operators
Python operator is a symbol that performs an operation on one or more operands. An operand is a variable or a value
on which we perform the operation. Python provides a variety of operators described as follows.

as
• Arithmetic Operators • Relational Operators • Assignment Operators • Logical Operators
• Membership Operators • Identity Operators • Bitwise Operators
(1) Arithmetic operators: Arithmetic operators are used to perform arithmetic operations between two operands. It

ak
includes +(addition), - (subtraction), *(multiplication), /(divide), %(remainder), //(floor division), and exponent
(**).
(a) Addition(+): It is used to add two operands. For example, if a = 20, b = 10 => a+b = 30
(b) Subtraction(-): It is used to subtract the second operand from the first operand. For example, a=30,

Pr
b=20>>> a-b=10
(c) Multiplication(*): It is used to multiply one operand with the other. For example, if a = 20, b = 10 => a
* b = 200
(d) Division(/): It returns the quotient after dividing the first operand by the second operand. For example, if
a = 20, b = 10 => a/b = 2. If quotient is coming in float value then division results in a floating-point
rs
value, for example, a=11,b=2 >>> a/b Output: 5.5
(e) Exponentiation(**): It returns the second operand power to first operand. a=2,b=3,a**b i.e. ab=8
e
(f) Floor Division(//): It returns the integer value of the quotient. It dumps the digits after the decimal. a =
10,b = 3 => a//b = 3
th

(g) Modulus(%): It returns the remainder after dividing the first operand by the second operand. For example,
a = 20, b = 10 => a%b = 0
Addition(+) Subtraction(-) Multiplication(*)
ro

Division(/) Exponentiation(**) Floor Division(//)


Modulus(%)
lB

(2) Relational Operators: Relational Operators are used to compare the value of two operands. It checks whether
an operand is greater than the other, lesser, equal, or a combination of those and returns the Boolean value i.e.
True or False.
When the condition for a relative operator is fulfilled, it returns True. Otherwise, it returns False. This return
a

value can be used in a further statement or expression.


(a) Less than(<): This operator checks if the value of first operand is less than the second operand. (i) 3<4
oy

Output True (ii) 15<10 Output False


(b) Greater than(>): It checks if value of first operand is Greater than the second operand.
>>> 3>4 Output: False
G

(c) Less than or equal to(<=): It checks if the value of first operand is Less than or equal to the second
operand. >>> 7<=7 Output: True
(d) Greater than or equal to(>=): It checks if the value of first operand is Greater than or equal to the second
operand. >>> 0>=0 Output: True
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 5
(e) Equal to(= =): It checks if the value of first operand is Equal to the second operand. 1 is equal to the
Boolean value True, other than 1 is equal to False.
(i) 5= =5 Output: True
(ii) 5= =8 Output: False
(f) Not equal to(!=): It checks if the value of two operands is not equal.

n
(i) 5! =5 Output: False
(ii) 3!=2 Output: True

ha
(3) Assignment operators: The assignment operators are used to assign the value of the right expression to the left
operand. It may manipulate the value by a factor before assigning it.
(a) Assign(=): It assigns the value of the right expression to the left operand., = = is used for comparing and
= is used for assigning.

as
a=10
print(a)
output :10

ak
(b) Add and Assign(+=): It increases the value of the left operand by the value of the right operand and assign
the modified value back to left operand.
a+ = b equal to a = a+ b

Pr
a+=10 equal to a=a+10

a=10 a=10 a=20


a+=20 b=20 a+=5*2
print(a) a+=b print(a)
rs
output :30 print(a,b) output:30
output:30,20
e
(c) Subtract and Assign(-=): It subtracts the value of the left operand by the value of the right operand and
assigns the modified value back to left operand.
th

a-= b equal to a = a- b
a-=10 equal to a=a-10
ro

a=20 a=10 a=20


a-=5 b=50 a-=5*2
print(a) a-=b print(a)
lB

output :15 print(a,b) output:10


output:-40,50

(d) Divide and Assign(/=): It divides the value of the left operand by the value of the right operand and assigns
a

the modified value back to left operand.


a/= b equal to a = a/ b
oy

a/=10 equal to a=a/10

a=20 a=10 a=20


a/=5 b=20 a/=5*2
G

print(a) a/=b print(a)


output :4.0 print(a,b) output:2.0
output:0.5,20

6 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
(e) Multiply and Assign(*=): It multiplies the value of the left operand with the value of the right operand
and assigns the modified value back to left operand.
a*= b equal to a = a*b
a*=10 equal to a=a*10
a=20 a=10 a=20

n
a*=5 b=20 a*=5*2
print(a) a*=b print(a)
output :100 print(a,b) output:200

ha
output:200,20

(f) Modulus and Assign(%=): It divides the value of the left operand by the value of the right operand and
assigns the remainder value back to left operand.

as
a%= b equal to a = a% b
a%=10 equal to a=a%10

a=20 a=10

ak
a%=5 b=20
print(a) a%=b
output :0 print(a,b)
output:10,20

Pr
(g) Exponent and Assign(**=): It performs exponentiation(power) the value of the left operand by the value
of the right operand and assigns the modified value back to left operand.
a**= b equal to a = a** b i.e. a=ab
a**=10 equal to a=a**10
rs
a=2 a=5
a**=3 b=2
e
print(a) a**=b
output :8 print(a,b)
th

output:25,2

(h) Floor-Divide and Assign(//=): It performs floor-division the value of the left operand by the value of the
right operand and assigns the modified value back to left operand.
ro

a//= b equal to a = a// b


a//=10 equal to a=a//10
lB

a=20 print(10//3)
a//=5 output:3
print(a)
output :4
a

(4) Logical Operators: The logical operators are conjunctions that can be used to combine more than one condition.
There are three Python logical operator – and, or, and not that come under python operators.
oy

(a) and: If all the expressions are true, then the condition will be true.
a=10 a=10
b=20 b=20
G

a<b and b>15 c=40


output : True a>b and b<c and c= =40
output: False

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 7
(b) or: If one of the expressions is true, then the condition will be true.
a=10 a=10 a=10
b=20 b=20 b=20
a<b or b>15 c=40 a>b or b>20
output : True a>b or b<c or c= =40 output :False

n
output: True
(c) not: This inverts the Boolean value of an expression. It converts True to False, and False to True. If an

ha
expression a is true then not (a) will be false and vice versa.
a=10 not 0 not “xyz” = =”xyz”
b=20 Output: True output: False
not a>b

as
output : True

(5) Membership Python Operators : Python membership operators checks whether the value is a member of a

ak
sequence.
(a) in: It is evaluated to be true if the first operand is found in the second operand (string, list, tuple or
dictionary).

Pr
“x” in “xyz” 5 in [10,20,30]
Output: True Output: False
(b) not in: It is evaluated to be true if the first operand is not found in the second operand (string, list, tuple
or dictionary).
rs
“x” not in “xyz” 5 not in [10,20,30]
Output: False Output: True
e

(6) Python Identity Operators: Identity operators are used to verify if two variables point to the same memory
location or not. Identity operators are of two types ‘is’ and ‘is not’.
th

(a) is: ’is’ operator returns true if both the operands point to same memory location. The variable having same
value points to same memory location; So, for them this operator returns a ‘true’.
ro

a=10 a=”xyz” “x” is “xyz”


b=10 b=”xyz” Output: False
a is b a is b
lB

Output :True output:True

(b) is not: is not operator returns true if both the operands point to different memory location. It is the opposite
of ‘is’ operator.
a

2 is not 2 “x” is not “xyz” 2 is not 2.0


Output :False Output: True Output:True
oy

(7) Bitwise Operator:


G

& | ^
Binary AND Binary OR Binary XOR

~ Binary Ones Complement << Binary Left Shift >> Binary Right Shift

8 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
28. Which of the following are valid operators in Python? [comptt 19]
(i) += (ii) ^ (iii) in (iv) && (v) between
(vi) */ (vii) is (viii) like
Ans. (i) += (ii) ^ (iii) in (vii) is
29. Which of the following are valid operators in Python: [2019]

n
(i) ** (ii) */ (iii) like (iv) ||
(v) is (vi) ^ (vii) between (viii) in

ha
Ans. (i) ** (v) is (vi) ^ (viii) in
30. Which of the following is valid arithmetic operator in Python: [SP 20]
(i) // (ii) ? (iii) < (iv) and
Ans. (i) //

as
31. Identify the valid arithmetic operator in Python from the following.
(i) ? (ii) < (iii) ** (iv) and [SP 21]
Ans. (iii) **

ak
32. How many types of Data Type available in Python.
Ans. Data Types

Text Type: string

Pr
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
rs
Set Types: set, frozenset
Boolean Type: bool
e
Binary Types: bytes, bytearray, memoryview
33. Write the names of any four data types available in Python. 2[2019]
th

Ans. Numbers Integer Boolean Floating Point Complex None Sequences


Strings Tuple List Sets Mappings Dictionary
ro

34. Consider the statement:


first_name = “Ayana”;
(i) What is the datatype of first_name ?
lB

(ii) Is 325 the same as “325” ? Give reason.


Ans. (i) String data type
(ii) No, 325 is a Number/Integer while “325” is a String.
35. Consider the statement :
a

fname = “Rishabh”;
(i) What is the datatype of fname ?
oy

(ii) Is 456 the same as “456” ? Give reason


Ans. (i) String data type
(ii) No, 456 is a Number/Integer while “456” is a string.
G

36. (i) Is 123 the same as 123.0 ? Give reason


(ii) Is “234” the same as “234.0” ? Give reason
Ans. (i) No, 123 is an Integer. And 123.0 is a floating type.
(ii) They are different strings and they are not of Number Datatype.
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 9
37. Write the data type of variables that should be used to store: 1[2018]
(i) Marks of students
(ii) Grades of students(Grade can be ‘A’ or ‘B’ or ‘C’)
Ans. (i) float/int (ii) string

2. Operator Precedence

n
38. What is the precedence of operators?
Ans. The precedence of an operator specifies how “tightly” it binds two expressions together. The precedence of the

ha
operators is important to know which operator should be evaluated first. The precedence table of the operators
in python is given below:
Operator Description

as
** The exponent operator is given priority over all the others used in the expression.
~+- The negation, unary plus and minus.
* / % // The multiplication, divide, modules, remainder, and floor division.

ak
+- Binary plus and minus
>> << Left shift and right shift

Pr
& Binary and.
^| Binary xor and or
<= < > >= Comparison operators (less than, less than or equal to, greater than, greater than
or equal to).
rs
<> == != Equality operators.
= %= /= //= -= +=
e
*= **= Assignment operators
is is not Identity operators
th

in not in Membership operators


not or and Logical operators
ro

39. Write the value that will be assigned to variable x after executing the following statement:
x = 3 + 36/12 + 2*5
lB

Ans. 16.0
40. Write the value that will be assigned to variable c after executing the following statement:
C = 25-5*4/2-10+4
Ans. 9.0
a

41. Write the value that will be assigned to variable x after executing the following statement:
oy

x = 20 -5 + 3 * 20/5
Ans. 27.0
42. Evaluate the following expressions: [SP 21]
(a) 6 * 3 + 4**2 // 5 – 8
G

(b) 10 > 5 and 7 > 12 or not 18 > 3


Ans. (a) 13 (b) False

10 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
3. Print function
The print function in Python is used to display the output of variables: string, lists, tuples, range, etc.
Following is the syntax of using the print function:
print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Where:

n
• The object can be strings, lists, tuple etc.
• The sep = ‘’ parameter specifies a space between multiple objects. You can use other than space by using this
parameter.

ha
• The end=’\\n\’ means in each call, the print function will end with a new line, if you want you can change that.
• The file=sys.stdout specifies where the print function should send the output. is sys.stdout.
• The flush keyword argument specifies whether to flush or not the output stream. The default value is false.

as
43. Give the output
(i) print(20,sep=”-“,end=”$”)
(ii) print(40,50,60,sep=”*“,end=”!”)
(iii) print(“hello,hi,bye”,sep=”*“,end=”!”)

ak
(iv) print(“hello”,”hi”,”bye”,sep=”*”,end=”!”)
(v) print(2>5,7<10,end=”@”)
(vi) print(“2*3,6*5”,sep=”%”)
(vii) print(2*3,6+5,sep=”+”)

Pr
Ans. (i) 20$ (ii) 40*50*60! (iii) hello,hi,bye! (iv) hello*hi*bye!
(v) False True@ (vi) 2*3,6*5 (vii) 6+11
4. Input() function
The input() method reads a line from input(usually user), converts into a string and returns it.
rs
The syntax of input() method is:
input([prompt])
The input() method takes a single optional argument:
e

prompt (Optional) - prompt is the string we wish to display on the screen. It is optional.
th

Practice Questions – I
44. What is the difference between mutable and immutable in Python?
Ans. Mutable object can be changed after it is created, and an immutable object can’t. Objects of built-in types like
ro

(int, float, bool, string, tuple, unicode) are immutable. Objects of built-in types like (list, set, dict) are mutable.
45. Distinguish between ‘/’ and ‘%’ operators.
Ans. ‘/’ divides first number with second number and returns the quotient.
lB

‘%’ divides first number with second number and returns the remainder.
46. Write the output of the following Python code: 2 [SP 18]
i=5
j=7
a

x=0
i=i+(j-1)
oy

x=j+1
print(x,”:”,i)
j=j**2
G

x=j+i
i=i+1
print (i,”:”,j)
Ans. 8 : 11 12 : 49
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 11
47. Give the output if a=10 and b=20
a=input(“enter no”)
b=input(“enter 2nd no”)
print(a+b)
Ans. 1020

n
48. Write a program to take two nos and swap two nos.
Ans. a=int(input(“enter a”))

ha
b=int(input(“enter b”))
a,b=b,a
print(a,b)
49. Write a program to take two numbers and show 2nd number is power of 1st . For example if 1st number is 5

as
and 2nd number is 3 then result is 53 = 125
Ans. a=int(input(“enter 1st no “))
b=int(input(“enter power”))

ak
print(a**b)
50. Write a program to take two nos and show the sum of these two nos.
Ans. a=int(input(“enter a”))
b=int(input(“enter b”))

Pr
print(a+b)
51. Write a program to take two float numbers and show the sum of these two.
Ans. a=float(input(“enter a”))
b=float(input(“enter b”))
rs
print(a+b)
52. Write a program to take first name and last name from user and show full name. For example if first name is
“Aman” and last name is “Sharma” then it will display “AmanSharma”(without space).
e

Ans. first=input(“enter 1st name”)


th

last=input(“enter last name”)


print(first+last)
53. Give the output
ro

(i) a=20
b=30
a,b=b+20,a+30
lB

print(a,b)
Ans. 50 50
(ii) a=20
b=30
a

a,c=b*10,a/10
print(a,b,c)
oy

Ans. 300 30 2.0


(iii) a=10
b=a*20
G

b,c=b*10,a%10
print(a,b,c)
Ans. 10 2000 0

12 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
Multiple Choice Questions – I
1. Which of the following can be used as valid variable identifier(s) in Python?
(i) total (ii) switch (iii) Que$tion (iv) global
2. Identify invalid variable name out of the following.
(i) While (ii) 123salary (iii) Big (iv) float

n
3. Which of the following is invalid operator in Python?
(i) += (ii) ^ (iii) in (iv) &&

ha
4. Identify invalid operator out of the following.
(i) between (ii) */ (iii) is (iv) //
5. What is the datatype of “321”?

as
(i) None (ii) Integer (iii) String (iv) List
6. Output of the following code is:
print(40,50,60,sep=”!“,end=”,”)
(i) 40,50,60! (ii) 40!50!60! (iii) 40!50!60, (iv) 40,50,60

ak
7. print(2*5,6+5,sep=”+”)
output of above code is
(i) 10,11 (ii) 10+11 (iii) 21 (iv) ”10”+”11”

Pr
8. Write the value that will be assigned to variable x.
x = 6 + 36/6 + 2*5
(i) 45.0 (ii) 17.0 (iii) 26.25 (iv) 22.0
9. Write the value that will be assigned to variable c.
rs
c = 25-5*4/2-10+5
(i) 10.0 (ii) 35.0 (iii) -2.5 (iv) -12.5
10. Write the value that will be assigned to variable a
e
a=20*5+3**2%2//5
(i) 101 (ii) 100 (iii) 1.9 (iv) None of these
th

11. Output of the following program is


a=”10”
ro

b=”20”
c=a+b
print(c)
lB

(i) “10”+”20” (ii) 30 (iii) ”10+20” (iv) 1020


12. Give the output
a,b=10,20
b,a=a,b
a

print(a,b)
(i) 10,20 (ii) 10,10 (iii) 20,10 (iv) 20,20
oy

13. Give the output


a=20
b=30
G

a,b=b+10,a+30
print(a,b)
(i) 30,60 (ii) 50,40 (iii) 60,50 (iv) 40,50

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 13
14. Give the output
a=5
b=20
a+=b
b-=a
print(a,b)

n
(i) 25,15 (ii) 25,5 (iii) 25,-5 (iv) 25,25
15. Give the output

ha
a=16
b=3
c=a/2**b
print(c)

as
(i) 512.0 (ii) 4.0 (iii) 2.0 (iv) 24.0

Answers

ak
1. (i) 2. (ii) 3. (iv) 4. (i) 5. (iii) 6. (iii) 7. (ii) 8. (iv) 9. (i) 10. (ii)
11. (iv) 12. (iii) 13. (iv) 14. (iii) 15. (iii)

5. Conditional Statement

Pr
Conditional Statement in Python performs different computations or actions depending on whether a specific Boolean
constraint evaluates to true or false. Conditional statements are handled by IF statements in Python.
(a) IF statement: In Python if statement is a statement which is used to test specified condition. The if statement
executes only when specified condition is true.
rs
The general Python syntax for a simple if statement is
if condition :
indentedStatementBlock
e
If the condition is true, then do the indented statements. If the condition is not true, then skip the indented
statements.
th

(b) if else statement:


The if statement accepts an expression and then executes the specified statemets If the condition is true. If the
condition is not true, then executes the specified statements indented below else.
The syntax of the if...else statement is −
ro

if expression:
statement(s)
else:
lB

statement(s)
(c) if-elif statement:
The elif statement allows to check multiple expressions for TRUE then execute a block of code as soon as one
of the conditions evaluates to TRUE.
a

syntax
if expression1:
oy

statement(s)
elif expression2:
statement(s)
G

elif expression3:
statement(s)
else:
statement(s)

14 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
54. Give the output
(i) Num = 6
Num = Num + 1
if Num > 5:
print(Num)
else:

n
print(Num+5)
Ans. 7

ha
(ii) N = 20
N = N + 1
if N<21:

as
print(N+10)
else:
print(N+15)
Ans. 36

ak
(iii) Age,Relatxation=24,6
ModiAge=Age-Relatxation
If ModiAge<18:
print(“Not eligible”)

Pr
else:
print(“Eligible”)
Ans. Eligible
55. The following code has some error(s). Rewrite the correct code underlining all the corrections made.
rs
(i) written=int(input(“enter written marks”))
interview=input(“enter interview marks”)
if (written<80 or interview <15)
e
print(“NotSelected”)
else:
th

print(“Selected”)
Ans. written=int(input(“enter written marks”))
interview=int(input(“enter interview marks”))
ro

if written<80 or interview <15:


print(“NotSelected”)
else:
lB

print(“Selected”)
(ii) marks = int(input(“enter marks”))
temperature = input(“enter temperature”)
if marks < 80 and temperature >= 40
a

print(“Not Good”)
else
oy

print(“OK”)
Ans. marks = int(input(“enter marks”))
temperature = int(input(“enter temperature”))
if marks < 80 and temperature >= 40:
G

print(“Not Good”)
else:
print(“OK”)

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 15
(iii) j=5
i= =j+5
if (i=j)
  print(“i and j are equal”)
else:
  print(“i and j are unequal”)

n
Ans.
j=5

ha
i=j+5
if i= =j:
print(“i and j are equal”)
else:

as
print(“i and j are unequal”)
56. Write the value of p after execution of the following code:
p=7

ak
q=2
if p>q:
p=p+2
p=p+1

Pr
Ans. 10
57. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the
code. [comptt 2020]

input(‘Enter a word’,W)
rs
if W = ‘Hello’

print(‘Ok’)
e
else:
print(‘Not Ok’)
th

Ans.
W=input(‘Enter a word’) //Error 1
if W == ‘Hello’ : //Error 2,Error 3
ro

print(‘Ok’)
else : //Error 4
print(‘Not Ok’)
lB

58. What is the difference between the following statements (i) and (ii)
(i) a = 5
(ii) if a = = 5:
x = 3
a

Ans. (i) variable a is being assigned the value 5


(ii) a is being checked for equality with 5
oy

OR
(i) assignment operator is used (ii) relational operator ‘= =’ is used.
59. What is the difference between statements (i) and (ii)
(i) t = 2
G

(ii) if t = = 2:
d = 3
Ans. (i) variable ‘t’ is being assigned the value 2 (ii) ‘t’ is being checked for equality with 2

16 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
OR
(i) assignment operator is used (ii) relational operator ‘==’ is used.

6. Loops
Loops are used to iterate over elements of a sequence, it is often used when a piece of code which you want to repeat
“n” number of time.

n
(a) For Loop

ha
A for loop is used for iterating over a sequence (i.e., is either a list, a tuple or a string).
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
Syntax:
for var in sequence:
statements(s)

as
else:
statements(s)
Here, var is the variable that takes the value of the item inside the sequence on each iteration.

ak
Else statement(s) will be executed when loop terminated normally(without break statement)
60. Give the output:
(i) for i in 1,2,3,4,5:

Pr
print(i)
Ans. 1
2
3
rs
4
5
(ii) for i in 1,3,10,15:
e
print(i)
Ans. 1
th

3
10
15
ro

(iii) for i in 1,3,10,15:


print(i)
lB

i=i+2
Ans. 1
3
10
a

15
61. Give the output
oy

(i) for i in range(1,5):


print(i)
Ans. 1
G

2
3
4

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 17
(ii) s=0
for i in range(1,10):
s=s+i
print(i,s,sep=”,”)
Ans. 9,45
62. Give the output

n
(i) for i in range(1,5):
print(i*i)

ha
Ans. 1
4
9
16

as
(ii) for i in range(5,25,5):
print(i*2)
Ans. 10

ak
20
30
40
(iii) for i in range(5,1,-1):

Pr
print(i*2)
Ans. 10
8
6
4
rs
(iv) for i in range(1,10,2):
print(i)
i=i+3
e

Ans. 1
3
th

5
7
9
ro

63. What will be displayed after the execution of the following loop?
Total,End=5,15;
for Turn in range(1,End,2):
lB

Total+=1;
print(Total)
print(Turn)
Ans. 12
a

13
oy

64. What will be displayed after the execution of the following loop?
sum,last=0,10
for C in range(1,last,2):
sum=sum+1;
G

print(sum)
print(C)
Ans. 5
9
18 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
65. Write the output that will be generated by the code given below:
for i in range(5,11,5):
t=i+3;
print(t)
Ans. 8

n
13

ha
66. What will be the values of variables ‘P’ and ‘Q’ after the execution of the following code?
Q=0;
for P in range(1,5,1):
Q+=P

as
Q=Q-1
print(P)
print(Q)

ak
Ans. 4
6
67. What will be the values of variables ‘m’ and ‘n’ after the execution of the following code?

Pr
n=5;
for m in range(5,10,1):
n+=m
rs
n=n-1
print(n)
print(m)
e
Ans. 35
9
th

68. What will be the value of A and B after execution of the following code?
A = 100
ro

for B in range(10, 13):


A+=B
lB

print(“A:”,A,”B:”,B) ;
Ans. A: 133 B: 12
69. What will be the value of num and num1 after execution of the following code?
num1=10
a

for num in range(100,102):


oy

num1=num+2
num1=num1-1
print(num)
G

print(num1)
Ans. 101
102

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 19
70. What will be the values of x and y after execution of the following code?
y=0;
for x in range(1,6):
y=x+1
y=y-1

n
print(x)
print(y)

ha
Ans. 5
5
71. Write the value that will be stored in variable sum after execution of following code?

as
sum=0
for i in range(9,5,-1):
if(i%3==0):
sum = sum + i

ak
else:
sum = sum - i
print(i,sum)

Pr
Ans. 6 0
72. What will be displayed after the following code is executed?
n=3;
p=1;
rs
if n < 0:
print(“Not Valid”)
else:
e

for i in range(1,n+1):
th

p = p* i;
print(n+p)
Ans. 9
ro

73. Write the value of C after executing the following code


R= 8;
C = 0;
lB

for P in range(1,R,3):
oddNum = P %2;
if oddNum == 1:
a

C= C+1
print(C)
oy

Ans. 2
(b) While loop
While loop repeats the sequence of actions many times until some condition evaluates to False
G

while condition:
block of statement(s)
The else part is executed if the condition in the while loop evaluates to False.

20 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
74. How many times will the following loop execute and give the output
z=7
sum=0;
while z<=12:
sum=sum+z

n
z=z+2
print(z)

ha
Ans. 3 times
11
75. How many times does the following while loop get executed?

as
K=5
L=36
while K<=L:
K+=6

ak
Ans. 6
76. How many times will the loop execute?
value1,value2=7,19;

Pr
while value1<=value2:
value1=value1+2
value2=value2-2
Ans. 4
rs
77. How many times will the following WHILE loop execute and what will be the value of sum after execution of
the following loop?
y,sum=7,0
e
while y<=15:
sum = sum + y
th

y = y+2
print(sum)
ro

Ans. loop will be executed 5 times and value of sum is 55


78. What will be the values of variables agg after execution of the following loops?
a=9
lB

agg=9
while(a>10):
agg+=a
a-=2
a

Ans. agg=9,
oy

79. What will be the values of variables sum after execution of the following loop?
v=6
sum=0
while v>3:
G

sum+=v;
v-=2
Ans. 10

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 21
80. What will be displayed after the execution of the following code?
G=1
while G<=5:
print(G+2)
G=G+1

n
Ans. 3
4

ha
5
6
7

as
81. What will be displayed after the execution of the following code?
z=4
while z<=8:

ak
print(z+3)
z=z+2
Ans. 7

Pr
9
11
82. Write the output that will be generated by the code given below:
i=7
rs
r=8
while i<=10:
print(r*i)
e

i=i+2
th

Ans. 56
72
83. Observe the following code carefully and find which statement will never get executed in the code:
ro

counter=1 #statement1
while counter<=15: #statement2
lB

if counter<15: #statement3
print(“Jump”) #statement4
else: #statement5
print(“Stop”) #statement6
a

counter+=4 #statement7
Ans. statement 6
oy

84. Find and write the output of the following python code: 1[SP 2019-20]
x = “abcdef”
i = “a”
G

while i in x:
print(i, end = “ “)
Ans. aaaaaa----- OR infinite loop

22 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
85. Write the value that will be stored in variable p after execution of following code. How many times will the
loop execute?
y,x,p = 3,5,0
while y > 0:
p = p + x

n
y = y-1
Ans. p=15

ha
3 times
86. What will be displayed after the following code is executed? Also write how many times will the loop execute.
a = 5;

as
b = 2;
while (b != 0):
r = a%b
a = b

ak
b = r
print(a)
Ans. 1

Pr
2 times
87. Write the value that will be stored in variable num and sum after execution of following code:
sum=0
num = -2
rs
while num < 1 :
sum = sum + num
e
num=num+1
Ans. num = 1 sum = -3
th

88. What will be displayed after the following code is executed?


ndigits = 0
ro

N = 35
while (N > 12):
ndigits = ndigits + 1
lB

N = N-10;
print(ndigits)
print(N)
Ans. 3
a

5
oy

89. What will be the final value of variable x after the following code is executed? [SP 18]
x=10
while x>1:
x=x//3
G

x=x+1
print(x)
Ans. 1

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 23
90. What will be the output displayed, when the following code is executed? [2018]
a=5
b = 2
while a < 20:
a = a + b

n
b = a - b
print(a,end=” “)

ha
Ans. 7 12 19 31
91. What will be the values of i and z after the following code is executed? [2018]
i = 0

as
z = 10
while i<10:
i=i+2
z=z-1

ak
print(i,z)
Ans. 10, 5
Theory

Pr
92. What do you understand by the term Iteration? [SP 2019-20]
Ans. Repeatation of statement/s finite number of times is known as Iteration.
93. Differentiate between break and continue statement with the help of an example. 2 [SP 18]
Ans. Break statement is used to terminate the execution of the loop, for example:
rs
for i in range(6):
if i = = 3:
e
break
print i
th

The output of the above code will be:


0
1
ro

2
The loop terminates when i becomes 3 due to break statement whereas, continue statement is used to force the
next iteration while skipping the statements in the present iteration.
lB

for i in range(6):
if i ==3:
continue
a

print i
The output of the above code will be
oy

0
1
2
G

4
5
continue statement forces next iteration when i becomes 3 , bypassing the print statement .Thus ,in the output 3
is missing.
24 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
7. LIST
The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items)
between square brackets. Important thing about a list is that items in a list need not be of the same type.

Creating a list
In Python programming, a list is created by placing all the items (elements) inside a square bracket [ ], separated by

n
commas. It can have any number of items and they may be of different types (integer, float, string etc.).

ha
Empty List
lt=[]
print (lt)
output

as
[]

Creating list with same type

ak
lt=[2,4,5]
lt1=[‘hello’,’hi’,’bye’]
lt2=[25.7,35.8,93.2]
print (lt)

Pr
print (lt1)
print (lt2)
output:
[2, 4, 5]
rs
[‘hello’, ‘hi’, ‘bye’]
[25.7, 35.8, 93.2]

List within list


e

lt=[[2,4,5],[‘hello’,’hi’,’bye’],25.7,35.8,93.2]
th

print (lt)
[[2, 4, 5], [‘hello’, ‘hi’, ‘bye’], 25.7, 35.8, 93.2]

List with different data types


ro

lt=[1,’rahul’,18,87.5]
print (lt)
lB


[1, ‘rahul’, 18, 87.5]

Access Elements
To retrieve an element of the list, we use the index operator ([]). Index starts from 0. Trying to access an element other
that this will raise an IndexError. The index must be an integer. We can’t use float or other types, this will result into
a

TypeError
oy

Python allows negative indexing for its sequences. The index of -1 refers to the last item, -2 to the second last item
and so on.
94. A List L contain the following values
L=[10,20,30,40,50,60,70,80]
G

show the output of following print statements


(i) print(L[1]) (ii) print(L[3]) (iii) print(L[-2]) (iv) print(L[-6]) (v) print(L[4],L[-3])

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 25
Ans. The index values of List are:
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1

(i) 20 (ii) 40 (iii) 70 (iv) 30 (v) 50 60

n
Using for loop

ha
95. A list lt is given below, show all contents of list using for loop
lt=[2,4,5]
Ans. for i in lt:
print(i)

as
2
4
5

ak
Using slicing
A slice is a subset of list elements.
my_list[start:stop,step]
where start is the index of the first element to include, stop is the index of the item to stop at without including it in

Pr
the slice and step sets the interval
96. Give the output
lt=[2,4,5,8,10,15]
print(lt[1:2])
rs
print(lt[:3])
print(lt[2:])
print(lt[:])
e
print(lt[2:-2])
print(lt[-2:-5:-1])
th

Ans. [4]
[2, 4, 5]
[5, 8, 10, 15]
ro

[2, 4, 5, 8, 10, 15]


[5, 8]
[10, 8, 5]
lB

Changed Item Value


We can use assignment operator (=) to change an item or a range of items.
97. Give the output of the following program
a

lt=[2,4,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
oy

lt[1]=9
lt2[0][2]=2
lt2[-1][0]=5
G

print(lt)
print(lt2)
Ans. [2, 9, 5, 8, 10, 15]
[[‘one’, ‘two’, 2], [5, 5, 6]]
26 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
Adding new Element(s)
By append method : Add an element to the end of the list
98. Give the output
lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]

n
lt.append(25)

ha
lt2.append(7)
for i in range (1,4):
lt.append(i*2)
print(lt)

as
print(lt2)
Ans. [1, 0, 5, 8, 10, 15, 25, 2, 4, 6]
[[‘one’, ‘two’, ‘three’], [4, 5, 6], 7]

ak
Adding tuple and list
99. Give the output

Pr
tup1=(7,8,9)
lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
lt.append(tup1)
rs
lt2.append(lt)
print(lt)
print(lt2)
e

Ans. [1, 0, 5, 8, 10, 15, (7, 8, 9)]


th

[[‘one’, ‘two’, ‘three’], [4, 5, 6], [1, 0, 5, 8, 10, 15, (7, 8, 9)]]

Using insert() method


ro

Addition of Element at specific Position


insert(position,no)
100. List lt and lt2 are given to you, write command to add 15 on position 1 in lt and add 8 on position 1 in lt2
lB

lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
Ans. lt.insert(1,15) # 1 is position, 15 is no to add
a

lt2.insert(1,8)
print(lt)
oy

print(lt2)
output
[1, 15, 0, 5, 8, 10, 15]
G

[[‘one’, ‘two’, ‘three’], 8, [4, 5, 6]]

Using extend method


Addition of multiple elements to the List at the end
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 27
101. Give the output
lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
lt.extend([20,34,66])
lt2.extend([4,8,6])

n
lt.extend(range(15,20))
print(lt)

ha
print(lt2)
Ans. [1, 0, 5, 8, 10, 15, 20, 34, 66, 15, 16, 17, 18, 19]
[[‘one’, ‘two’, ‘three’], [4, 5, 6], 4, 8, 6]

as
Using slicing
You can add elements in list by using slicing
102. Give the output

ak
L=[10,20,30,40,50]
L[len(L):]=45,67
print(L)

Pr
Ans. [10, 20, 30, 40, 50, 45, 67]

Remove Item(s) from List


Using remove() method : Removes an item from the list
rs
103. Write a command to delete 1st occurance of 5 from list lt
lt=[1,0,5,8,10,5]
Ans. lt.remove(5)
e
print(lt)
[1, 0, 8, 10, 5]
th

Using pop() method


The pop() method removes the specified index, (or the last item if index is not specified):
ro

104. Give the output


lt=[1,0,4,5,8,2,3,10,5]
lB

lt.pop() #remove last no


lt.pop(2) #remove no of index no 2
lt.pop(4)
print(lt)
a

Ans. [1, 0, 5, 8, 3, 10]


clear(): is used to clear all items from list
oy

105. Removes all items from the list lt


lt=[1,0,4,5,8,2,3,10,5]
Ans. lt.clear()
G

print(lt)
output
[]
28 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
Using del
The del keyword removes the specified index
106. Give the output
lt=[1,0,4,5,8,2,3,10,5]
del lt[1]

n
print(lt)
Ans. [1, 4, 5, 8, 2, 3, 10, 5]

ha
The del keyword can also delete the list completely:
107. Give the output
lt=[1,0,4,5,8,2,3,10,5]

as
del(lt)
print(lt)
Ans. NameError: name ‘lt’ is not defined

ak
Sorting
108. (i) Write program in python to sort items in a list lt in ascending order
lt=[1,0,4,5,8,2,3,10,5]

Pr
Ans. lt.sort()
print(lt)
Output;
[0, 1, 2, 3, 4, 5, 5, 8, 10]
rs
(ii) Write program in python to sort items in a list lt in descending order
lt=[1,0,4,5,8,2,3,10,5]
e
Ans. lt.sort(reverse=True)

print(lt)
th

Output:
[10,8,5,5,4,3,2,1,0]
ro

Index()
Returns the index of the first matched item
109. Give the output
lB

lt=[1,0,4,5,8,2,3,10,5]
print(lt.index(5))
Ans. 3
a

Reverse():
Reverse the order of items in the list
oy

110. Write a command to show the contents of list lt in reverse order


lt=[1,0,4,5,8,2,3,10,5]
Ans. lt.reverse()
G

print(lt)
output:
[5, 10, 3, 2, 8, 5, 4, 0, 1]

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 29
sum(),min(),max(),count()
111. Write a program in pyhon to display the sum, maximum value, maximum value and no of items in list lt
lt=[1,0,4,5,8,2,3,10,5]
Ans. a=sum(lt)
b=max(lt)

n
c=min(lt)
d=lt.count(5)

ha
print (a)
print (b)
print (c)
print (d)

as
38
10
0

ak
2

Output :List
112. Find and write the output of the following python code : 2 [D 15]

Pr
for Name in [“Jayes”, “Ramya”, “Taruna”, “Suraj”]:
print (Name)
if Name[0]== “T”:
break
rs
else:
print (“Finished”)
print (“Got it!”)
e
Ans. Jayes
Finished
th

Ramya
Finished
Taruna
ro

Got it!
113. Give the output 2 [OD 15]
lB

for Name in [‘John’, ‘Garima’,’Seema’,’Karan’]:


print (Name)
if Name[0]==’S’:
break
else:
a

print (‘Completed!’)
oy

print(‘Weldone!’)
Ans. John
Completed!
Garima
G

Completed!
Seema
Weldone!

30 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
114. Find and write the output of the following Python code: [D 17]
STR = [“90”,”10”,”30”,”40”]
COUNT = 3
SUM = 0
for I in [1,2,5,4]:
S = STR[COUNT]

n
SUM = float (S)+I
print (SUM)

ha
COUNT-=1
Ans. 41.0
32.0

as
15.0
94.0
115. Find and write the output of the following Python code : 2[comptt 17]
L1 = [100,900,300,400,500]

ak
START = 1
SUM = 0
for C in range (START,4):

Pr
SUM = SUM + L1[C]
print (C,”:”,SUM)
SUM = SUM + L1[0]*10
print (SUM)
Ans. 3 : 1600
rs
2600
116. Find and write the output of the following python code: 2 [OD 17]
e
TXT=[“20”,”50”,”30”,”40”]
CNT = 3
th

TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
ro

TOTAL = float (T) + C


print (TOTAL)
CNT-=1
lB

Ans. 47.0
35.0
54.0
26.0
a

117. What output will be generated when the following Python code is executed? [SP 17]
oy

def ChangeList():
L=[ ]
L1=[ ]
L2=[ ]
G

for i in range(1,10):
L.append(i)
for i in range(10,1,-2):

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 31
L1.append(i)
for i in range(len(L1)):
L2.append(L1[i]+L[i])
L2.append(len(L)-len(L1))
print (L2)
ChangeList()

n
Ans. [11, 10, 9, 8, 7, 4]
118. Write the output of the following Python program code: [SP 18]

ha
Data=[“D”,”o”,” “,”I”,”t”,” “,”@”,” “, “1”,”2”,”3”,” “,”!”]
for i in range(len(Data)-1):
if(Data[i].isupper()):

as
Data[i]=Data[i].lower()
elif (Data[i].isspace()):
Data[i]=Data[i+1]
print(Data)

ak
Ans. [‘d’, ‘o’, ‘I’, ‘i’, ‘t’, ‘@’, ‘@’, ‘1’, ‘1’, ‘2’, ‘3’, ‘!’, ‘!’]
119. Find and write the output of the following python code: 2 [D 16]
Numbers=[9,18,27,36]
for Num in Numbers:

Pr
for N in range(1, Num%8):
print(N,”#”,end=”” )
print()
Ans. 1 #
rs
1 #2 #
1 #2 #3 #
120. Find and write the output of the following python code: 2 [OD 16]
e
Values=[10,20,30,40]
for Val in Values:
th

for I in range(1, Val%9):


print(I,”*”,end= “” )
print()
ro

Ans. 1 *
1 *2 *
1 *2 *3 *
lB

121. Find and write the output of the following python code: 2 [D 18]
Data = [“P”,20,”R”,10,”S”,30]
Times = 0
Alpha = “”
a

Add = 0
for C in range(1,6,2):
oy

Times= Times + C
Alpha= Alpha + Data[C-1]+”$”
Add = Add + Data[C]
G

print (Times,Add,Alpha)
Ans. 1 20 P$
4 30 P$R$
9 60 P$R$S$
32 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
122. Give the output [2][comptt 2020]
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0 :
M[i] //= 5
if M[i]%3 == 0 :

n
M[i] //= 3

ha
L=[ 25,8,75,12]
ChangeVal(L,4)
for i in L :
print(i, end=’#’)

as
Ans. 5#8#5#4#
123. Give the output
(i) lt=[2,4,5]

ak
lt1=[‘sun’,’mon’,’tue’]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
print(lt[0])
print(lt1[-2])

Pr
print(lt2[0][1])
print(lt2[-1][-1])
print(lt2[0][1])
Ans. 2
mon
rs
two
6
e
two
(ii) lt2=[[‘one’,’two’,’three’],[4,5,6]]
th

for i in lt2:
for j in i:
print(j,end=””)
ro

print()
Ans. onetwothree
456
lB

(iii) lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
lt[1]=lt[0]
lt[0]=lt[1]
a

lt2[-1][0]=lt[2]+3
print(lt)
oy

print(lt2)
Ans. [1, 1, 5, 8, 10, 15]
[[‘one’, ‘two’, ‘three’], [8, 5, 6]]
G

(iv) L=[10,20,30,40,50]
L[1:3]=45,67
print(L)
Ans. [10, 45, 67, 40, 50]
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 33
(v) lt=[1,0,4,5,8,2,3,10,5]
for i in range(1,5):
lt.remove(i)
print(lt)
Ans. [0, 5, 8, 10, 5]
(vi) lt=[1,0,4,5,8,2,3,10,5]

n
lt2=[[‘one’,’two’,’three’],[5,4,6]]
lt2[0].sort()

ha
lt.sort(reverse=True) #descending order
print(lt)
print(lt2)

as
Ans. [10, 8, 5, 5, 4, 3, 2, 1, 0]
[[‘one’, ‘three’, ‘two’], [4, 5, 6]]
(vii) lt2=[[‘one’,’two’,’three’],[5,4,6]]
lt2.reverse()

ak
print(lt2)
[[5, 4, 6], [‘one’, ‘two’, ‘three’]]
8. TUPLE

Pr
A Tuple is a collection of Python objects separated by commas.
• Tuples are written with round brackets(parentheses are optional), whereas lists use square brackets.
• Tuple is immutable unlike lists which are mutable. we cannot change the elements of a tuple once it is assigned
whereas, in a list, elements can be changed.
• Tuple indices start at 0.
rs
• A tuple can have any number of items and they may be of different types (integer, float, list, string, etc.).
124. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect? [SP 21]
e
(a) print(T[1])
(b) T[2] = -29
th

(c) print(max(T))
(d) print(len(T)
Ans. (b) T[2]= -29 (as tuple is immutable)
ro

125. A tuple is declared as


T = (2,5,6,9,8)
What will be the value of sum(T)? [SP 21]
lB

Ans. 30
9. STRING
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
However, Python does not have a character data type, a single character is simply a string with a length of 1. Strings
a

in Python can be created using single quotes or double quotes or even triple quotes.
126. The following code has error(s), rewrite the correct code underlining all the correction made:
oy

str1=Seema
for b range (0;3,1):
print(str1+b,last=”*”)
Ans.
G

str1=”Seema”
for b in range (0,3,1):
print(str1+str(b),end=”*”)

34 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
127. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the
code [D 17]
TEXT=””GREAT
DAY””
for T in range[0,7]:

n
printTEXT(T)
print T+TEXT

ha
Ans.
TEXT=”GREAT”
DAY=””

as
for T in range(0,7):
print (TEXT[T])
print (T,TEXT)
128. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the

ak
code.
STRING=””WELCOME
NOTE””

Pr
for S in range[0,8]:
print STRING(S)
print S+STRING
Ans. STRING=”WELCOME”
NOTE=” “
rs
for S in range(0,5):
print (STRING[S])
print (S,STRING)
e

129. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the
th

code. [OD 17]


STRING=””WELCOME
NOTE””
ro

for S in range[0,8]:
print STRING(S)
print S+STRING
lB

Ans. STRING=”WELCOME”
NOTE=” “
for S in range(0,8):
print (STRING[S])
a

print (S,STRING)

10. Dictionary
oy

A dictionary in Python is just like a dictionary in the real world. Python Dictionary are defined into two elements Keys
and Values.
Features of Dictionary:
G

• Keys are unique within a dictionary while values may not be.
• The values of a dictionary can be of any type.
• The keys must be of an immutable data type such as strings, numbers, or tuples.

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 35
• Keys will be a single element
• Each key-value pair maps the key to its associated value.
• Dictionary can be defined by enclosing a comma-separated list of key-value pairs in curly braces ({}).
• A colon (:) separates each key from its associated value:
• Dictionary is mutable means additon and modification can be done.

n
130. Give the output

ha
dic1={1:”aman”,3:”abha”,2:”shanker”}
dic2={‘name’:”aman”,’rollno’:[1,2,3,4]}
dic3={‘name’:(“raj”,”aman”,”pahul”),’rollno’:[1,2,3,4]}
print(dic1.items())

as
print(dic2.items())
print(dic3.items())
Ans. dict_items([(1, ‘aman’), (3, ‘abha’), (2, ‘shanker’)])

ak
dict_items([(‘name’, ‘aman’), (‘rollno’, [1, 2, 3, 4])])
dict_items([(‘name’, (‘raj’, ‘aman’, ‘pahul’)), (‘rollno’, [1, 2, 3, 4])])

131. Create dictionary dic1 with rollno (1,5,7) as keys and names(“aman”,”abha”,”shanker”) as respective values.

Pr
Ans. dic1={1:’aman’,5:’abha’,7:’shanker’}
132. Give the output:
dic1={‘r’:’red’,’g’:’green’,’b’:’blue’}
rs
for i in dic1:
print (i,end=’’)
Ans. output:
e

rgb
th

133. Write the names of the immutable data objects from the following: [1][comptt 2020]
(i) List (ii) Tuple (iii) String (iv) Dictionary
Ans. (ii) Tuple (iii) String
ro

134. Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1,2,3 and corresponding values
as ‘Reena’, ‘Rakesh’, ‘Zareen’ respectively. [1][comptt 2020]
lB

Ans. ClassRoll = {1:”Reena”, 2:”Rakesh”, 3: ”Zareen”}


135. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are Monday, Tuesday and
Wednesday respectively. [SP 21]
Ans. Day={1:’monday’,2:’tuesday’,3:’wednesday’}
a

Theory
oy

136. What is a NameError in Python? [1][comptt 2020]


Ans. NameError is a syntax error raised when a local or global name used in a Python code is not found.
137. What is a TypeError in Python? [1][comptt 2020]
G

Ans. TypeError is a syntax error raised, when an operation or function is applied to an object of inappropriate type in
a Python code.

36 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
Multiple Choice Questions – II
1. Which of the option out of (i) to (iv) is the correct data type for the variable Vowels as defined in the following
Python statement:
Vowels = (‘A’, ‘E’, ‘I’, ‘O’, ‘U’)
(i) List (ii) Dictionary (iii) Tuple (iv) Array [1] [comptt 2020]

n
2. Which is the correct form of declaration of dictionary? [SP 2019-20]
(i) Day={1:’monday’,2:’tuesday’,3:’wednesday’}

ha
(ii) Day=(1;’monday’,2;’tuesday’,3;’wednesday’)
(iii) Day=[1:’monday’,2:’tuesday’,3:’wednesday’]
(iv) Day={1’monday’,2’tuesday’,3’wednesday’] 1

as
3. Identify the valid datatype of L:
L = [1, 23, ‘hi’, 6] [SP 2019-20]
(i) list (ii) dictionary (iii) array (iv) tuple
4. Krrishnav is looking for his dream job but has some restrictions. He loves Delhi and would take a job there if

ak
he is paid over `40,000 a month. He hates Chennai and demands at least `1,00,000 to work there. In any another
location he is willing to work for `60,000 a month. The following code shows his basic strategy for evaluating
a job offer.
Code: [CBSE QB]

Pr
pay= _________
location= _________
if location == “Mumbai”:
print (“I’ll take it!”) #Statement 1
rs
elif location == “Chennai”:
if pay < 100000:
print (“No way”) #Statement 2
e
else:
print(“I am willing!”) #Statement 3
th

elif location == “Delhi” and pay > 40000:


print(“I am happy to join”) #Statement 4
elif pay > 60000:
ro

print(“I accept the offer”) #Statement 5


else:
print(“No thanks, I can find something better”) #Statement 6
lB

On the basis of the above code, choose the right statement which will be executed when different inputs for pay
and location are given.
(i) Input: location = “Chennai”, pay = 50000
(a) Statement 1 (b) Statement 2 (c) Statement 3 (d) Statement 4
a

(ii) Input: location = “Surat” ,pay = 50000


(a) Statement 2 (b) Statement 4 (c) Statement 5 (d) Statement 6
oy

(iii) Input: location = “Any Other City”, pay = 1


(a) Statement 1 (b) Statement 2 (c) Statement 4 (d) Statement 6
(iv) Input: location = “Delhi”, pay = 500000
G

(a) Statement 6 (b) Statement 5 (c) Statement 4 (d) Statement 3


(v) Input: location = “Lucknow”, pay = 65000
(a) Statement 2. (b) Statement 3 (c) Statement 4 (d) Statement 5

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 37
5. Consider the following code and answer the questions that follow: [CBSE QB]
Book={1:’Thriller’, 2:’Mystery’, 3:’Crime’, 4:’Children Stories’}
Library ={‘5’:’Madras Diaries’,’6’:’Malgudi Days’}
(i) Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has written
the following command:

n
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:

ha
(a) Book[2]=’Crime Thriller’ (b) Book[3]=’Crime Thriller’
(c) Book[2]=(’Crime Thriller’) (d) Book[3] =(‘Crime Thriller’)
(ii) The command to merge the dictionary Book with Library the command would be:

as
(a) d=Book+Library (b) print(Book+Library)
(c) Book.update(Library) (d) Library.update(Book)
(iii) What will be the output of the following line of code:

ak
print(list(Library))
(a) [‘5’,’Madras Diaries’,’6’,’Malgudi Days’] (b) (‘5’,’Madras Diaries’,’6’,’Malgudi Days’)
(c) [’Madras Diaries’,’Malgudi Days’] (d) [‘5’,’6’]
(iv) In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following command:2

Pr
in Book He gets the answer ‘True’.
Now to check whether the name ‘Madras Diaries’
exists in the dictionary Library, he uses the following command:
‘Madras Diaries’ in Library
rs
But he gets the answer as ‘False’. Select the correct reason for this:
(a) We cannot use the in function with values. It can be used with keys only.
e
(b) We must use the function Library.values() along with the in operator
(c) We can use the Library.items() function instead of the in operator
th

(d) Both (b) and (c) are correct.


(v) With reference to the above declared dictionaries, predict the output of the following code fragments
ro

Code 1 Code 2
Library=Book Library=Book.copy()
Library.pop(2) Library.pop(2)
lB

print(Library) print(Library)
print(Book) print(Book)

(a)
a

Code 1 Code 2
oy

{1: ‘Thriller’, 2: {1: ‘Thriller’, 3:


‘Mystery’, 3: ‘Crime’, ‘Crime’, 4: ‘Children
4: ‘Children Stories’} Stories’}
G

1: ‘Thriller’, 2: {{1: ‘Thriller’, 3:


‘Mystery’, 3: ‘Crime’, ‘Crime’, 4: ‘Children
4: ‘Children Stories’} Stories’}

38 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
(b)
Code 1 Code 2

{2:’Mystery’} {1: ‘Thriller’, 3:


‘Crime’, 4: ‘Children
Stories’}

n
{1: ‘Thriller’, 2: {1: ‘Thriller’, 3:

ha
‘Mystery’, 3: ‘Crime’, ‘Crime’, 4: ‘Children
4: ‘Children Stories’} Stories’}

(c)

as
Code 1 Code 2
{1: ‘Thriller’, 3: {1: ‘Thriller’, 3:
‘Crime’, 4: ‘Children ‘Crime’, 4: ‘Children
Stories’} Stories’}

ak
{1: ‘Thriller’, 3: {1: ‘Thriller’, 2:
‘Crime’, 4: ‘Children ‘Mystery’, 3: ‘Crime’, 4:
Stories’} ‘Children Stories’}

Pr
(d)
Code 1 Code 2

{1: ‘Thriller’, 3: {1: ‘Thriller’, 3:


‘Crime’, 4: ‘Children ‘Crime’, 4: ‘Children
rs
Stories’} Stories’}

{1: ‘Thriller’, 2: {1: ‘Thriller’, 3:


e
‘Mystery’, 3: ‘Crime’, ‘Crime’, 4: ‘Children
4: ‘Children Stories’} Stories’}
th

6. Priyank is a software developer with a reputed firm. He has been given the task to computerise the operations
for which he is developing a form which will accept customer data as follows: [CBSE QB]
ro

The DATA TO BE ENTERED IS :


(A) Name
lB

(B) Age
(C) Items bought( all the items that the custom bought)
(D) Bill amount
a

(i) Choose the most appropriate data type to store the above information in the given sequence.
(a) string, tuple, float, integer (b) string, integer, dictionary, float
oy

(c) string, integer, integer, float (d) string, integer, list, float
(ii) Now the data of each customer needs to be organised such that the customer can be identified by name
followed by the age, item list and bill amount. Choose the appropriate data type that will help Priyank
G

accomplish this task.


(a) List (b) Dictionary
(c) Nested Dictionary (d) Tuple

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 39
(iii) Which of the following is the correct way of storing information of customers named ‘Paritosh’ and
‘Bhavesh’ with respect to the option chosen above?
(a) a.customers= {‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409, ‘Bhavesh’:
45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99 }
(b) customers={‘Paritosh’:[24,[‘Printed Paper’, ‘ Penstand’], 3409], ‘Bhavesh’:

n
[45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’],
8099.99] }

ha
(c) customers= [‘Paritosh’:24,‘Printed Paper’, ‘ Penstand’, 3409, ‘Bhavesh’:
45,‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’, 8099.99 ]
(d) customers=(‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409, ‘Bhavesh’:

as
45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99 )
(iv) In order to calculate the total bill amount for 15 customers, Priyank
Statement 1. must use a variable of the type float to store the sum.

Statement 2. may use a loop to iterate over the values

ak
(a) Both statements are correct.
(b) Statement 1 is correct, but statemnt 2 is not.
(c) Both statements are incorrect.

Pr
(d) Statement 1 is incorrect but statement 2 is correct.
7. Write the value that will be stored in variable t after the execution of the following code. How many times will
the loop execute?
rs
sum = score = 0
while score <=3:
score = score +1
e

sum = sum + score


th

t = sum // 3
print(t)
(i) Value of t will be 4 Loop executes 3 times
ro

(ii) Value of t will be 3 Loop executes 4 times


(iii) Value of t will be 3 Loop executes 3 times
(iv) Value of t will be 4 Loop executes 4 times
lB

8. Observe the following code carefully and find which statement will never get executed in the code?
t=1 #statement1
while(t<=15): #statement2
a

if t>13: #statement3
oy

print(“Something”) #statement4
else: #statement5
print(“Pass”) #statement6
t+=3 #statement7
G

(i) statement 1 (ii) statement 2


(iii) statement 3 (iv) statement 4

40 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
9. Write the value of sum1 after execution of the following WHILE loop :
i = 1
sum1 = 0
while i<10:
sum1 =sum1+ i

n
i =i+2
(i) 24 (ii) 25 (iii) 26 (iv) 27

ha
10. Give the output
for i in range(1,10,3):
print(i,sep=”-”,end=”*”)

as
(i) 1-4-7* (ii) 1-4-7-10* (iii) 1*4*7* (iv) 1*4*7*10
11. If the following code is executed, what will be the output of the following code? [SP 21]
name=”ComputerSciencewithPython”

ak
print(name[3:10])
(i) mputerS   (ii) puterSc   (iii) mputerScie   (iv) puterScien
12. m = 16

Pr
m = m+1
if m<15:
print(m)
else:
print(m+15)
rs
(i) 32   (ii) 16   (iii) 17   (iv) 31
e
Answers
1. (iii) 2. (i) 3. (i)
th

 4. (i) (b) (ii) (d) (iii) (d) (iv) (c) (v) (d)
5. (i) (b) (ii) (d) (iii) (d) (iv) (b) (v) (c)
ro

6. (i) (d) (ii) (b) (iii) (b) (iv) (a)


7. (ii) 8. (iv) 9. (ii) 10. (iii) 11. (i) 12. (i)
a lB
oy
G

Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 41

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy