Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Problem 4: Write \'prob4.py\' to print a month, such as the following Jun

ID: 3849650 • Letter: P

Question

 Python Problem 4:  Write 'prob4.py' to print a month, such as the following       June 2017      Mo Tu We Th Fr Sa Su       1  2  3  4       5  6  7  8  9 10 11       12 13 14 15 16 17 18       19 20 21 22 23 24 25       26 27 28 29 30   Your prob4.py will take the month and year as command line arguments.  Running your prob4.py like this:         $ python prob4.py 6 2017  will generate the above calendar.  Python command line arguments are string type by default, so the month and year command line arguments will have to be cast to integer with (int).  See the following sections of the notes:    . "Python Intro"    . "Python Syntax - command line arguments". 

Explanation / Answer

Python 2.7 code:

import sys
import calendar
yy = int(sys.argv[1])
mm = int(sys.argv[2])
print(calendar.month(yy, mm))

Sample Output:


>python test.py 2017 6
June 2017
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30


>python test.py 2017 5
May 2017
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31