www_scribd
www_scribd
Q. Sub
No. Q. N.
Answer Marking
Scheme
1 Attempt any FIVE of the following: 10 M
a) Enlist applications for python programming. 2M
language. application,
• Maya, a powerful integrated 3D modeling and animation system,
provides a Python One applicationcripting API.
• Linux Weekly News, published by using a web application written
in Python.
• Google makes extensive use of Python in its Web Search Systems.
• The popular YouTube video sharing service is largely written in
Python programming.
• The NSA uses Python for cryptography and intelligence analysis.
• iRobot uses Python programming to develop commercial and
military robotic devices.
• The Raspberry Pi single-board computer promotes Python
programming as its educational language.
• Nextflix and Yelp have both documented the role of Python in their
software infrastructures.
• Industrial Light and Magic, Pixar and others uses Python in the
production of animated movies.
• Desktop GUI Applications
• Image Processing Applications
• Scientific and Numeric Applications
• Audio and Video Based Applications
• 3D CAD Applicationsfor 1 M each
Page No: 1 | 20
user. efinition 1
M,
• Data hiding is a software development technique specifically used
in Object-Oriented any two
Programming (OOP) to hide internal object details (data members).
• Data hiding includes a process of combining the data and functions
into a single unit Advantages 1
to conceal data within a class by restricting direct access to the data
from outside the M
class.
Advantages of Data Hiding
• Data hiding ensures exclusive data access to class
members and protects object integrity by preventing
unintended or intended changes.
• Data hiding is also known as information hiding. An
object's attributes may or may not be visible outside
the class definition.
• Data hiding also minimizes system complexity for
increase robustness by limiting interdependencies
between software requirements.
• The objects within the class are disconnected from irrelevant data.
• It heightens the security against hackers that are unable to access
confidential data.
• It helps to prevent damage to volatile data by hiding it from the
public.
• A user outside from the organization cannot attain the access to the
data.
• Within the organization/ system only specific users
get the access. This allows better operation.
e) State use of namespace in python. 2M
Ans • Namespaces bring you three advantages: they group names into
logical orrect/relevant containers, they prevent clashes between
duplicate names, and third, they use 2 M provide context to
names.
Page No: 2 | 20
2. readline([n]) Method:
The readline() method just output the entire line whereas
readline(n) outputs at most n bytes of a single line of a
file. It does not read more than one line. Once, the end of
file is reached, we get empty string on further reading.
Example: For readline
( ) method.
f=open("sample.txt","r")
print(f.readline()) # read first line
followed by\n print(f.readline(3))
print(f.readline())
g) Explain two ways to add objects / elements to list.
2M
2.
extend() Method: The extend() method extends a list by appending
items. We can add several items using extend() method.
Example: Program for extend() method.
>>>list1=[10, 20, 30, 40]
>>>list1
[10, 20, 30, 40]
>>> list1.extend([60,70]) #add elements at the end of list
>>> list1
[10, 20, 30, 40, 60, 70]
M (any two methods)
Page No: 3 | 20
Page No: 4 | 20
import p1 print(p1.add(10,20))
print(p1.sub(20,10))
Output:
30
10
rite module 2
and Import 2 M
Page No: 6 | 20
Page No: 7 | 20
Page No: 8 | 20
Example:
for i in
range(1, 4):
print(i)
else: # Executed because no break
in for print("Finally Exit”)
Output:
1
2
3
4M
Page No: 9 | 20
Page No: 10 | 20
Page No: 11 | 20
tell(): tell() returns the current position of the file pointer from the
beginning of the file.
Syntax: file.tell()
Example:
f=
open("demofile.tx
t", "r") # points at
the start
print(f.tell())
Page No: 12 | 20
Ans with open('first.txt', 'r') as f: # Open the first file for reading
contents = f.read() # Read the contents of the file
2.
Set Intersection: The intersection of two sets is the set of all the
common elements of
both the sets. You can use the ‘&’ operator to find the intersection of a
Python set.
>>> first_set = {1, 2, 3, 4, 5, 6}
>>> second_set = {4, 5, 6, 7, 8, 9}
>>> first_set.intersection(second_set)
{4, 5, 6}
>>> first_set & second_set # using the ‘&’ operator
{4, 5, 6}
3.
Set Difference
The difference between two sets is the set of all the elements in first set
that are not present
in the second set. You would use the ‘–‘ operator to achieve this in
Python.
>>> first_set = {1, 2, 3, 4, 5, 6}
>>> second_set = {4, 5, 6, 7, 8, 9}
>>> first_set.difference(second_set)
{1, 2, 3}
>>> first_set - second_set # using the ‘-‘ operator
{1, 2, 3}
>>> second_set - first_set
{8, 9, 7}
4.
Set Symmetric Difference: The symmetric
difference between two sets is the set of all the elements
that are either in the first set or the second set but not in
both. You have the choice of using either the
symmetric_difference() method or the ^ operator to do
this in Python.
>>> first_set = {1, 2, 3, 4, 5, 6}
>>> second_set = {4, 5, 6, 7, 8, 9}
>>> first_set.symmetric_difference(second_set)
{1, 2, 3, 7, 8, 9}
Page No: 13 | 20
ny 6 building blocks=6M
Eg: a,b,c=5,10,15
2)
Reserved Words
The following list shows the Python keywords. These
are reserved words and cannot use them as constant or
variable or any other identifier names. All the Python
keywords contain lowercase letters only.
3)
Indentation: Python provides no braces to indicate
blocks of code for class and function definitions or flow
control. Blocks of code are denoted by line indentation,
which is compulsory.
The number of spaces in the indentation is variable,
but all statements within the block must be indented
the same amount. For example –
if True:
print
"True"
else:
print "False"
4)
Python Types: The basic types in Python are String
(str), Integer (int), Float (float), and Boolean (bool).
There are also built in data structures to know when you
learn Python. These data structures are made up of the
basic types, you can think of them like Legos, the data
structures are made out of these basic types. The core
data
Page No: 14 | 20
_dict = {
'a': 'Sally sells sea
shells', 'b': 'down
by the seashore'
}
Page No: 15 | 20
5)
Control structures: Control structures are used to
determine the flow of execution of a Python program.
Examples of control structures in Python include if-else
statements, for and while loops, and try-except blocks.
6)
Functions: Functions are reusable blocks of code that
perform specific tasks. In Python, functions are defined
using the def keyword.
7)
Modules: Python modules are files that contain Python
code and can be imported into other Python programs to
reuse code and simplify development.
8)
Packages: Packages are collections of related Python
modules that can be installed and imported together.
Packages are commonly used in Python for organizing
and distributing libraries and tools.
c) Write a program illustrating use of user defined package
in python. 6 M
Ans # student.py
class Student:
def __init__(self, student): self.name = student['name'] self.gender =
student['gender'] self.year = student['year']
def get_student_details(self):
eate package: 2m
Importing ackages: 2m
Logic: 2m (Any
def get_faculty_details(self):
return f"Name: {self.name}\nSubject: {self.subject}"
# testing.py
# importing the Student and Faculty classes from respective files from
student import Student
from faculty import Faculty
an consider)
Page No: 16 | 20
Output :
Name:
ABC
Gender:
Male
Year: 3
Name: XYZ
Subject: Programming
def __str__(self):
return f"{self.name}({self.rollno})"
Output:
ABC 32
Create Class: 3m
Display Method: 3m
Page No: 17 | 20
labrador.display()
Output:
I can eat
My name is Rohu
Search
· ·
Any other suitable program can consider
0ratings 5Kviews 47downloads
Class creation: 2m
Logic: 2m
Listing: 2m
Explanation of any two function: 4m
(2 M each)
Page No: 18 | 20
output:
Set after updating: {'s', 'f', 'e', 'g', 'k'}
discard():
Removes the element from the set
Example:
s = {'g', 'e', 'k', 's'}
print('Set before
discard:', s)
s.discard('g')
print('\nSet after discard g:', s)
Output:
Set before discard: {'s', 'e', 'k', 'g'}
Set after discard g: {'s', 'e', 'k'}
remove():
Removes the specified element from the set. If the
specified element not found, raise an error.
Example:
s = {'g', 'e', 'k', 's'}
print('Set before
remove:', s)
s.remove('e')
print('\nSet after remove e:', s)
Output:
Set before remove: {'s', 'k', 'e', 'g'}
Set after remove e: {'s', 'k', 'g'}
clear():
Removes all elements from the set
Example:
s = {'g', 'e', 'k', 's'}
print('Set before
clear:', s) s.clear()
print('\nSet after clear:', s)
Output:
Set before clear: {'g',
'k', 's', 'e'} Set after
clear: set()
Page No: 19 | 20
Output:
original set: {'k', 's', 'g', 'e'}
Copied set: {'k', 's', 'g', 'e'}
Output:
The union of two sets is: {1, 2, 3, 4, 5, 6, 7, 8}
Output:
nums1 - nums2: {1, 2, 3}
nums2 - nums1: {8, 6, 7}
Output:
apple
Page No: 20 | 20
PDF 100%(2)
PHPS24Modelanswerpaper
37pages
PDFN oratingsyet
mad-w-23-mobile-application-
development-22617-winter-2023-
model-answer-papermad-22617
49pages
PDF0 % (2)
Csss24ModelAnswerPaperofS u
m m e r 2024ExamCss
31pages
PDFN oratingsyet
SolutionsManualDataStructuresWithC
++ UsingSTL2ndEditionFordPDF
9pages
PDFN oratingsyet
Lab9Strings:MDJ11103-
ComputerProgrammingLaboratoryMod
ule
6pages
PDF0 % (1)
ImportantInstructionsToExaminers::
EnlistApplicationsForPythonProgram
ming
20pages
PDFN oratingsyet
AllPythonModelAnswerPaper
89pages
PDF1 0 0 % (2)
S23MadMads23ModelAnswerP a
p p e r -1
49pages
PDF1 0 0
% (1)
22617_S-24
34pages
PDF 67%(3)
2024SummerModelAnswer
24pages
PDFN oratingsyet
22617(1)
58pages
PDFN oratingsyet
SUM23-ModelAnswer
26pages
Showmore
About Support
AboutScribd,Inc.H e lp/FAQ
Everand:Ebooks &Accessibility
Audiobooks
Purchasehelp
SlideShare
AdChoices
Joinourteam!
Weandour10IABTCFpartnersstoreandaccess
informationonyourdeviceforthefollowingpurposes:s
t o r eand/
oraccessinformationonadevice,a d ver
tisingandcontentmeasurement,audiencer esear
ch,andservicesdevelopment,personaliseda d
vertising,andpersonalisedcontent.Personaldatam
aybeprocessedtodothefollowing:usepreciseg e
ContactusSocial
olocationdataandactivelyscandevicec h a
racteristicsforidentification.OurthirdpartyIABT
C F partnersmaystoreandaccessinform
ationony o u r devicesuc
hasIPaddressanddevicec haracteristics.OurIABT
CFPartnersmayprocessthisp ersonaldataonthebas
isoflegitimateinterest,orw ithyourconsent.You
maychangeorwithdrawyourp r eferencesatany
timebyclickingonthecookieicono r link;
Instagra
however,asaconsequence,youmaynotseer elevan
m
tadsorpersonalizedcontent.
Legal
Ourwebsitemayusethesecookiesto: Facebook
Terms
Measuretheaudienceoftheadvertisingono
u r website,withoutprofiling Pinterest
PrivacyC
Displaypersonalizedadsbasedonyourn
avigationandyourprofile
opyright
Personalizeoureditorialcontentbasedonyo
urnavigation
Allowyoutosharecontentonsocialnetworkso
r platformspresentonourwebsite
Sendyouadvertisingbasedonyourlocation
PrivacyPolicyThi
rdParties
CustomizeYourChoices
AcceptAll
ContinueWithoutAccepting