Programming With Python Summer 2023
Programming With Python Summer 2023
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______________________________________________________________________________________________
___ -SUMMER – 2023 EXAMINATION
examiners:
22616
1) The answers should be examined by key words and not as word-to-word as given in
the model answer scheme.
2) The model answer and the answer written by candidate may vary but the
examiner may try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be
given more Importance (Not applicable for subject English and
Communication Skills.
4) While assessing figures, examiner may give credit for principal components
indicated in the figure. The figures drawn by candidate and model answer may
vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the
assumed constant values may vary and there may be some difference in the
candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of
examiner of relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other
program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in
English/Marathi and Bilingual (English + Marathi) medium is introduced at first
year of AICTE diploma Programme from academic year 2021-2022. Hence if the
students in first year (first and second semesters) write answers in Marathi or
bilingual language (English +Marathi), the Examiner shall consider the same
and assess the answer based on matching of concepts with model answer.
Q. Sub Answer Marking
No. Q. Scheme
N.
Ans The default constructor is simple constructor which does not Explanation
accept any arguments. It’s definition has only one argument 1 M,
which is a reference to the instance being constructed. Example
1M
Example 1: Display Hello message using default constructor.
class Student:
def show(self,name):
print("Hello",name)
s1 = Student()
s1.show("Student1")
Output:
Ans • We can make a new directory using the mkdir() method. Explanation
• This method takes in the path of the new directory. If the full 2M
path is not specified, the new directory is created in the
current working directory.
Syntax: os.mkdir(“newdir”)
Example:
>>> import os
>>> os.mkdir("testdir")
Print is a statement'''
Ans • The continue statement in Python returns the control to the Explanation
beginning of the while loop. 2M,
• The continue statement rejects all the remaining statements Example
in the current iteration of the loop and moves the control 2M
back to the top of the loop.
Syntax: continue
i=0
while i<10:
i=i+1
if i==5:
continue
print("i= ",i)
Output:
i=1
i=2
i=3
i=4
i=6
i=7
i=8
i=9
i=10
• sum(list)
Calculates sum of all the elements of list.
Example:
>>>list1
[1, 2, 3, 4, 5]
>>>sum(list1)
15
• min(list)
It returns the item that has the minimum value in a list.
Example:
> list1
[1, 2, 3, 4, 5]
> min(list1)
1
• list(seq)
It converts a tuple into a list.
Example:
> list1
[1, 2, 3, 4, 5]
> list(list1)
[1, 2, 3, 4, 5]
• abs(n)
It returns the absolute value of a number.
Example:
> abs(10)
10
• all()
The all() function returns True if all items in an iterable are true,
otherwise it returns False.
Example:
> x=[True, True, True]
> all(x)
True
• any()
The any() function returns True if any item in an iterable are true,
otherwise it returns False. If the iterable object is empty, the any()
function will return False. Example:
> x=[True, False, True]
> any(x)
True
• bin()
The bin() function returns the binary version of a specified integer.
The result will always start >>> bin(10)
Example:
'0b1010'
with the prefix 0b.
• bool()
The bool() function returns the boolean value of a
specified object.
Example:
>>> bool(1)
True
• exp()
The method exp() returns returns exponential
of x: ex.
x: This is a numeric expression.
Example:
>>> math.exp(1)
2.718281828459045
>>>
Output:
Enter Number: 5
The factorial of 5 is 120
Page No: 8 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
____________________________________________________________________________________
______________
new_tup1 = tup2 logic 4
M
new_tup2 = tup1
return new_tup1, new_tup2
# Input two tuples
tuple1 = tuple(input("Enter the elements of the first tuple (separated by
commas):").split(","))
b = 6 # binary: 0110
result = a & b
print(result) # Output: 2 (binary: 0010)
2) Bitwise OR (|): Performs a bitwise OR operation on the corresponding bits of two
numbers. Each bit of the output is 0 if the corresponding bits of both operands
are 0; otherwise, it is 1.
Example:
a = 10 # binary: 1010
b = 6 # binary: 0110
result = a | b
print(result) # Output: 14 (binary: 1110)
3) Bitwise XOR (^): Performs a bitwise XOR (exclusive OR) operation on the
corresponding bits of two numbers. Each bit of the output is 1 if the
corresponding bits of the operands are different; otherwise, it is 0.
Example:
a = 10 # binary: 1010
b = 6 # binary: 0110
result = a ^ b
print(result) # Output: 12 (binary: 1100)
4) Bitwise NOT (~): Performs a bitwise NOT operation on a single operand, which
inverts all the bits. It returns the complement of the given number.
Example:
a = 10 # binary: 1010
result = ~a
print(result) # Output: -11 (binary: -1011)
5) Bitwise left shift (<<): Shifts the bits of the left operand to the left by a
specified number of positions. Zeros are shifted in from the right side.
Example:
a = 10 # binary: 1010
result = a << 2
print(result) # Output: 40 (binary: 101000)
6) Bitwise right shift (>>): Shifts the bits of the left operand to the right by a
Ans readline(): This method reads a single line from the file and readline()
returns it as a string. It moves the file pointer to the next line after explanation
reading. If called again, it will read the subsequent line. for 1 M and
Example
# Open the file in read mode for 1 M
file = open("example.txt", "r") and
# Read the first line readlines()
explanation
line1 = file.readline() for 1 M and
Example
print(line1) for 1 M
Example:
# Open the file in read mode
file = open("example.txt", "r")
lines = file.readlines()
def get_info(self):
info = f"Make: {self.make}, Model: {self.model}, Year:
{self.year}"
return info
def start_engine(self):
print("Engine started!")
# Call the method that does not require any additional parameters
my_car.start_engine() # Output: Engine started!
4. Attempt any THREE of the following: 12 M
Ans List
Lists are Tuple Any 4
mutable correc
Tuples are
t point
immutable
4M
e implication of iterations is Time- The implication of iterations is comparatively
consum
# Main program
try:
num1 = int(input("Enter the numerator: "))
num2 = int(input("Enter the denominator: "))
except MyException as e:
print("Exception:", e.message)
Note: Any correct program of user defined
exception can be considered. Output:
Enter the numerator: 10
Enter the denominator: 0
Exception: Division by zero is not allowed!
Enter the numerator: 10
Enter the denominator: 5
Result: 2.0
Ans Modules are primarily the (.py) files which contain Python Explanation
programming code defining functions, class, variables, etc. 2 M and
with a suffix .py appended in its file name. use 2 M
• A file containing .py python code is called a module.
• If we want to write a longer program, we can use file where
we can do editing, correction. This is known as creating a
script. As the program gets longer, we may want to split it into
several files for easier maintenance.
list.append(numbers)
output:
Enter number 10
Enter number 20
Enter number 30
Enter number 40
Enter number 50
Example:
set1 = {1, 2, 3}
set2 = {2, 3, 4}
intersection_set = set1.intersection(set2)
print(intersection_set) # Output: {2, 3}
3) Difference:
Difference operation on two sets set1 and set2 returns all the elements
which are present on set1 but not in set2.
Example:
set1 = {1, 2, 3, 4, 5}
set2 = {3, 4}
difference_set = set1.difference(set2)
print(difference_set) # Output: {1, 2, 5}
4) add(element):
This function adds an element to a set.
Example:
fruits = {"apple", "banana", "cherry"}
fruits.add("orange")
print(fruits) # Output: {'apple', 'banana', 'cherry', 'orange'}
5) remove(element):
This function removes an element from a set.
Example:
numbers = {1, 2, 3, 4, 5}
numbers.remove(3)
print(numbers) # Output: {1, 2, 4, 5}
6) clear():
This function removes all elements from a set, making it an
empty set. Example:
numbers = {1, 2, 3, 4, 5}
numbers.clear()
print(numbers) # Output: set()
7) isdisjoint():
The isdisjoint() method in Python's set class is used to check whether two
sets have any common elements. It returns True if the sets are disjoint (i.e.,
they have no common elements), and False otherwise. Example:
# Example 1
set1 = {1, 2, 3, 4}
set2 = {5, 6, 7}
set3 = {3, 4, 5}
# Example 2
fruits = {"apple", "banana", "orange"}
colors = {"red", "green", "blue"}
# Example 3
setA = {1, 2, 3}
setB = {4, 5, 6}
self.department = ""
self.mobile_no = ""
def read_student_info(self):
self.name = input("Enter student name: ")
self.roll_no = input("Enter roll number: ")
self.department = input("Enter department: ")
self.mobile_no = input("Enter mobile number: ")
def print_student_info(self):
print("Student Information:")
print("Name:", self.name)
print("Roll Number:", self.roll_no)
print("Department:", self.department)
print("Mobile Number:", self.mobile_no)
Ans In inheritance objects of one class procure the properties of objects of another
class. Inheritance provide code usability, which means that some of the new
features can be added to the code while using the existing code. The mechanism
of designing or constructing classes from other classes is called inheritance.
• The new class is called derived class or child class and the class from
which this derived class has been inherited is the base class or parent
class.
• In inheritance, the child class acquires the properties and can access all the data
members and functions defined in the parent class. A child class can also provide
its specific implementation to the functions of the parent class.
Syntax:
class A:
# properties of class A
class B(A):
# class B inheriting property of class A
# more properties of class B
Example:
# Base class
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print("Animal speaks")
print("Dog barks")
print("Cat meows")