PRIP 4.3 Sumita Arora Solutions | Class 12 Computer Science

Here are PRIP 4.3 Sumita Arora Solutions for class 12 Computer Science. To view Sumita Arora solutions for all chapters, visit here.

Q.1: Mark created following directory structure for his module namely chk:
chk 
  |____work.py
  |___test 
        |__newwork.py

He has copied the folder’s link to site-packages folder of Python but still the following command is giving error:

In [1] : import chk 
Traceback (most recent call last):
File " <ipython-input-1-c6d47c0933ec>", line 1, in module> import chk
ModuleNotFoundError: No module named ‘chk’

(a) What is the possible reason of above error ?
Answer: 

  • import statement shows error because of absence of __init__.py file
  • __init__.py is for packages. A package contains a collection of related modules.
  • Files named __init__.py are used to mark directories on disk as Python package directories.
  • The __init__.py file is usually empty

Note:
Since Python 3.3
Allowing implicit namespace packages means that the requirement to provide an __init__.py file can be dropped completely
The old way with __init__.py files still works as in Python 2.
i.e. above question has executed on python2, if you try it on python3.3+ it will work fine without __init__.py
for version above python3.3 no need of __init__.py in chk but required in test to import modules from test

for more visit here

(b) Rectify above problem.
Answer:  Add empty __init__.py file in chk folder and in test folder

(c) After rectifying, write command to import work module of above shown chk package
Answer: 

from chk import work
OR
import chk.work
OR
import chk.work as w

(d) After rectifying, write command to import newwork module of above shown chk package
Answer:

from chk.test import newwork 
OR
import chk.test.newwork
OR
import chk.test.newwork as nw
Q.2: Create a package as per following:
mailsys/
           |----_init_.py
           |---- deliver.py # contains function send_mail(), get_mail(), draft), outbox(), inbax()
           |___archive
                  |__init_.py 
                  |___Oldmail.py # contains functions fiveyr(), starred()


After creation, this should be importable in a program with import statement. It should also have proper docstring so that help() function gives proper information about it.

a) Complete code of delivery.py (make assumption)
Answer:

#deliver.py
"""
deliver

functions related to delivery of mails

"""
def send_mail():
    """
    send_mail

    shows all sent mails 
   
    """
    print("called send_mail")

def get_mail():
    """
    get_mail

    shows all received mails 
   
    """
    print("called get_mail")

def draft():
    """
    draft

    shows all drafted mails 

    """
    print("called outbox")

def outbox():
    """
    outbox

    shows all outbox mails 

    """
    print("called outbox")

def inbox():
    """
    inbox

    shows all inbox mails 

    """
    print("called inbox")

(b) Complete code of oldmail.py (make assumptions)
Answer:

#Oldmail.py

"""
Oldmail

contains functions to access old mails

"""

def fiveyr():
    """
    fiveyr

    used to show mails from last five years 
   
    """
    print("used to show mails from last five years")

def starred():
    """
    starred

    use to show all starred mails 

    """
    print("use to show all starred mails")

(c) Write command to display details of module delivery
Answer:

>>> import mailsys.deliver
>>> help(mailsys.deliver)
>>> from mailsys import deliver
>>> help(deliver)

(d) Write command to import get_mail() function
Answer:

>>> from mailsys.deliver import get_mail
>>> help(get_mail)

(e) Write command to import these modules : deliver and oldmail
Answer:

>>> from mailsys import deliver
>>> from mailsys.archive import Oldmail
>>> help(Oldmail)
>>> help(deliver)

(f) Write command to run draft() function
Answer:

>>> from mailsys import deliver
>>> deliver.draft()
Output:
called draft

(g) Write command to run fiveyr() function
Answer:

>>> from mailsys.archive import Oldmail
>>> Oldmail.fiveyr()
Output:
used to show mails from last five years

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You cannot copy content of this page