In: Computer Science
Modularity
Note: The documentation you’ll be looking at for this part of the lab was written for
professional programmers, not programming novices, so it may include a number of
references to complex technical topics or details. Don’t be surprised, discouraged, or
concerned if parts of it don’t make a lot of sense right now; much of it will become clearer
as the semester progresses. For now, just do the best you can to look for information that
you can use to answer the question(s) below.
Functions also introduce the concept of modularity, where a program can be broken up
into multiple smaller pieces; each of these modules contains one or more functions that can
be used to perform a small part of the overall task (and which can be reused by other
programs). Python includes a large library of modules, each of which includes useful pre
written functions that programmers can use in their own programs with the use of an
import statement. The “Python Standard Library” Web page, available at <https://
docs.python.org/3/library/index.html>, contains a full list of these “bundled” modules (the
list starts at the “Text Processing Services” bullet point and continues until the end of the
page).
In class to date, we’ve used or made reference to three of these modules: random,
string, and math. Choose TWO of the other modules listed on the “Python Standard
Library” page. For each module:
1. Identify the name of the module and briefly summarize what general purpose it serves.
2. Select THREE functions from this module. List each function’s name and briefly
describe what it does.
3. Give an example of a type of program (real or hypothetical) for which this module is
either essential or extremely useful.
Calender
this module can be used to output a calender and do a lot of additional processes and calculations related to a calender, dates, months,year etc.It can output an editable calender in HTML.
isleap() - method is used to return True if year is a leap year, otherwise False.
HTMLCalender(firstweekday=0) - this method can be used to print a calender in html
calender.monthcalender( TheYear, TheMonth)- Returns a matrix representing a month’s calendar. Each row represents a week, days outside of the month are represented by zeros.
This module will be helpful while creating a program for schedule organizer, or to display a time table, where a calender is a crucial part of the application.
Random
This module is used to generate pseudo random numbers
seed()- intializes a random number generator
randrange() - outputs a random number in the given range
sample() - outputs a random element from a given sequence
This module will be helpful while creating a game that involves use of dice, like snake and ladder , ludo to generate a random number from 1 to 6 as an output of the dice.