BRAHMDEVDADA MANE POLYTECHNIC, BELATI SOLAPUR
DEPARTMENT OF COMPUTER TECHNOLOGY
Model Answer (Class Test 1)
Academic Year:2024-25 Program Code:CM6I
Course Name: Programming with Python Course Code: 22616
Duration: 1Hr. Max. Marks: 20
Date 10/02/2025
Q. Sub Answers Marking
No. Q. N Scheme
1
Attempt any Five 10 Toatal
Marks
a. List identity operators in python 2M
Ans. Identity operators are used to compare the objects, not if they are equal,
but if they are actually the same object, with the same memory location.
Identity operator in Python are.
• is :- Returns True if both variables are the same object.
2M
e.g. x is y
• is not :- Returns True if both variables are not the same object.
e.g. x is not y
b. How to give single and multiline comment in Python 2M
Ans. Single line comment: Single-line comments are created simply by beginning a
line with the hash (#) character, and they are automatically terminated by the
end of line.
Example:
# print is a statement
print(‘Hello Python’)
Multi line comment: Python multi-line comment is a piece of text enclosed in a
delimiter (""") Triple quotation marks.
Example:
""" Multi-line comment used 2M
print("Python Comments") """
or
To add a multiline comment you could insert a # for each line:
Example:
#This is a comment
#written in
#more than just one line
print("Hello, World!")
c. List data types used in Python. 2M
Ans. Data types in Python programming includes:
• Numbers: Represents numeric data to perform mathematical operations.
• String: Represents text characters, special symbols or alphanumeric data.
• List: Represents sequential data that the programmer wishes to sort, merge etc.
• Tuple: Represents sequential data with a little difference from list. 2M
• Dictionary: Represents a collection of data that associate a unique key with
each value.
• Boolean: Represents truth values (true or false).
d. List Python features. (Any four) 2M
Ans. • Easy to Learn and Use
• Interactive Mode
• Expressive Language
• Interpreted Language
• Cross-platform Language
• Portable
• Free and Open Source
2M
• Object-Oriented Language
• Extensible
• Large Standard Library
• GUI Programming Support
• Integrated
• Databases
• Scalable
e. Describe Tuples in Python. 2M
Ans. A tuple is a collection of items which is ordered and unchangeable. Tuples are 2M
the sequence or series values of different types separated by commas (,).
Example: tup1=(10,20,30)
f. Describe indentation in Python. 2M
Ans Indentation refers to the spaces at the beginning of a code line. Python
indentation refers to adding white space before a statement to a particular block
of code. In another word, all the statements with the same space to the right,
belong to the same code block.
2M
g. List Python Building Blocks and Running Simple Python Script to Display 2M
“All the best for Your Unit Test”
Ans 1. Keywords
2. Identifiers
3. Indentation
4. Variables 2M
5. Comments
print (“All the best for Your Unit Test”)
Q. Sub Answers Marking
No. Q. N Scheme
2
Attempt any Five 12 Total
Marks
a. Describe bitwise operators in Python with example. 4M
Ans. Bitwise operators acts on bits and performs bit by bit operation. Assume
a=10 (1010) and b=4 (0100)
Operator Meaning Description Example
& Binary This operation a &b =
AND performs AND 1010 &
operation 0100 =
between 0000 =0
operands.
Operator
copies a bit, to
the result, if it
exists in both
operands
| Binary OR This operation a|b = 1010
performs OR | 0100 =
operation 1110 = 14
between
operands. It
copies a bit, if
it exists in
either operand.
4M (for any
^ Binary This operation a^b=1010 four, 1M each)
XOR performs XOR ^ 0100 =
operations 1110 =14
between
operands. It
copies the bit,
if it is set in
one operand
but not both.
~ Binary It is unary ~a= ~ 1010
Ones operator and = 0101
Complement has the effect
of 'flipping'
bits i.e.
opposite the
bits of
operand.
<< Binary Left The left a<<2=
Shift operand's 1010 << 2
value is =101000 =
moved left by 40
the number of
bits specified
by the right
operand.
>> Binary The left a>>2 =
Right Shift operand's 1010 >> 2
value is =0010 = 2
moved right
by the number
of bits
specified by
the right
operand.
b. 4M
Explain decision making statements If-else, if-elif-else with example
Ans. 1. The if-else statement: if statements executes when the
conditions following if is true and it does nothing when the
condition is false. The if-else statement takes care of a true as
well as false condition.
Syntax:
If condition:
Statement(s)
else:
Statement(s)
Example:
i=20
if(i<15):
print(" less than 15")
else:
print("greater than 15")
Output:
greater than 15
2. if-elif-else (ladder) statements: Here, a user can decide among
multiple options. The if statements are executed from the top 4M (2m for if
down. As soon as one of the conditions controlling the if is true, else and 2m for
the statement associated with that if is executed, and the rest of if-elif-else)
the ladder is bypassed. If none of the conditions is true, then the
final else statement will be executed.
Syntax:
if (condition-1):
statement
elif (condition-2):
statements
.
.
elif(condition-n):
statements
else:
statements
Example:
i = 20
if (i == 10):
print ("i is 10")
elif (i == 15):
print ("i is 15")
elif (i == 20):
print ("i is 20")
else:
print ("i is not present")
Output:
i is 20
c. 4M
Write Python code for finding greatest among four numbers.
Ans.
list1 = [ ]
num = int(input("Enter number of elements in list: "))
for i in range(1, num + 1):
element = int(input("Enter elements: "))
[Link](element)
Any correct
print("Largest element is:", max(list1)) logic program
4M
Output:
Enter number of elements in list: 4
Enter elements: 10
Enter elements: 20
Enter elements: 45
Enter elements: 20
Largest element is: 45
d. Compare list and dictionary. (Any 4 points)
4M
Ans. List Dictionary
List is a collection of index Dictionary is a hashed structure
Any four point,
values pairs as that of array in of key and value pairs.
1 M for 1 point
c++.
List is created by placing Dictionary is created by placing
elements in [ ] separated by elements in { } as “key”:”value”,
commas “, “ each key value pair is separated
by commas “, “
The indices of list are integers The keys of dictionary can be of
starting from 0. any data type.
The elements are accessed via The elements are accessed via
indices. key values.
The order of the elements entered There is no guarantee for
are maintained. maintaining order.
Lists can duplicate values since Dictionaries cannot contain
each values have unique index. duplicate keys but can contain
duplicate values since each value
has unique key.
Average time taken to search a Average time taken to search a
value in list takes O[n]. key in dictionary takes O[1].
Average time to delete a certain Average time to delete a certain
value from a list takes O[n]. key from a dictionary takes O[1].
e. Write python program to perform following operations on Set
4M
i) Create set ii) Access set Element iii) Update set iv) Delete set
Ans. # To Create set
4M for any
S={10,20,30,40,50}
suitable
program
# To Access Elements from set
print (S) 2m
#To add element into set using add method
[Link](60)
print(S)
#To update set using update method
[Link](['A','B'])
print(S)
#To Delete element from Set using discard() method 2m
[Link](30)
print(S)
#To delete element from set using remove() method
[Link]('A')
print(S)
#To delete element from set using pop() method
[Link]()
print(S)
output:
{50, 20, 40, 10, 30}
{50, 20, 40, 10, 60, 30}
{'B', 50, 20, 'A', 40, 10, 60, 30}
{'B', 50, 20, 'A', 40, 10, 60}
{'B', 50, 20, 40, 10, 60}
{50, 20, 40, 10, 60}
f. Write basic operations of list.
4M
Ans 1)Accessing values in list: Any two
Accessing elements liters from a list in Python is a method to get values that operations:
are stared in the list at a particular location or index. 2 M for each
To access values in lists, use the square brackets for slicing along with the
index or indices to obtain value available at that index.
Example: accessing list values.
>>> list1 = ["one","two",3,10,"six",20]
>>> list1[0]
'one'
>>> list1[1:3]
['two', 3]
2) Deleting Values in List
The pop() method in Python is used to remove a particular item/element from
the given index in the list. The pop() method removes and returns the last item
if index is not provided. This helps us implement lists as stacks (first in, last
out data structure).
>>> list= [10, 20, 30, 40]
>>> list
[10, 20, 30, 40]
30
>>> list
[10, 20, 40]
>>> [Link]()
40
>>> list
[10, 30]
3. Updating Lists:
• List are mutable, meaning their elements can be changed or updated unlike
string or tuple.
• Mutability is the ability for certain types of data to be changed without
entirely recreating it. Using mutable data types can allow programs to operate
quickly and efficiently.
• Multiple values can be added into list. We can use assignment operator (=) to
change an item or a range of items.
• We can update items of the list by simply assigning the value at the
particular index position. We can also remove the items from the list using
remove() or pop() or del statement.
>>> list1= [10, 20, 30, 40, 50]
>>> list1
[10, 20, 30, 40, 50]
>>> list1[0]=0 # change 0th index element
>>> list1
[0, 20, 30, 40, 50]
4 Indexing
There are various ways in which we can access the elements of a list.
List Index: We can use the index operator [] to access an item in a list. Index
starts from 0. So, a list having 5 elements will have index from 0 to 4.
Example:
>>> list1=[10,20,30,40,50]
>>> list1[0]
10
>>> list1[4]
50
>>> list1[1:3]
[20, 30]
5. List Slicing
The slicing operator returns a subset of a list called slice by specifying two
indices, i.e. start and end.
Syntax:
List_variable[start_index:end_index]
Example:
>>> l1=([10,20,30,40,50])
>>> l1[1:4]
[20, 30, 40]
g. Write python program to illustrate if else ladder.
4M
Ans i = 20 4M (for correct
if (i == 10): program and
print ("i is 10") logic)
elif (i == 15):
print ("i is 15")
elif (i == 20):
print ("i is 20")
else:
print ("i is not present")
Output:
i is 20