CS303E Homework 4

Instructor: Dr. Bill Young
New Due Date: Friday, September 24, 2021 at 11:59pm

Assignment

Computing the numbers of days in a month is pretty simple. There's even a common rhyme to remember how to do it (Days per month). Your task is to find the number of days in a month. Prompt the user to enter the month and year and display the number of days in that month. You can assume that the user enters ``reasonable'' integers. You can assume that the month will be in [1..12] and the year will be a four-digit positive integer [1000..9999]. Yes, I know that our modern system of dates didn't exist in the year 1000 (and some years might be anomalies) but we'll just assume the current system for all years from 1000 on. Be sure to take account of leap years. For that, you can adapt the code from slideset 4.

Below are a couple of sample runs:

> python DaysInMonth.py
Please enter a year: 2000
Please enter a month: 2
February 2000 has 29 days
Here's another example:
> python DaysInMonth.py
Please enter a year: 2021
Please enter a month: 9
September 2021 has 30 days
Note that this assignment is largely intended to reinforce your understanding of selection (if) statements. Use selection, for example, to convert the month's number to the month's name. Don't use lists or other Python constructs not yet covered in class though week 4.

Turning in the Assignment:

The program should be in a file named DaysInMonth.py. Submit the file via Canvas before the deadline shown at the top of this page. Submit it to the assignment weekly-hw4 under the assignments sections by uploading your python file.

Your file must compile and run before submission. It must also contain a header with the following format:

# File: DaysInMonth.py
# Student: 
# UT EID:
# Course Name: CS303E
# 
# Date Created:
# Date Last Modified: 
# Description of Program: 

If you submit multiple times to Canvas, it will rename your file name to something like Filename-1.py, Filename-2.py, etc. Don't worry about that; we'll grade the latest version.

An Aside:

This part is just for your amusement; it doesn't require any work on your part. If you're on a Linux system (and probably on MacOS as well), there's a command line utility named cal that will show the calendar for the current month. You can also specify a month and year and it will show the calendar for that month (or just a year and it will show the entire year).
> cal
   September 2021     
Su Mo Tu We Th Fr Sa  
          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        
                      
> cal 10 2021
    October 2021      
Su Mo Tu We Th Fr Sa  
                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                    
It's pretty smart; here's the entry for September, 1752, the month the Julian calendar was replaced by the Gregorian calendar. Eleven days were dropped to make an adjustment. This is just for your amusement and a clever trip to amuse your friends. Don't build this into your program.
> cal 9 1752
   September 1752     
Su Mo Tu We Th Fr Sa  
       1  2 14 15 16  
17 18 19 20 21 22 23  
24 25 26 27 28 29 30  
So, if you were a Linux system programmer implementing this homework and the user entered month 9 and year 1752, the program should display:
September 1752 has 19 days
But your program, at least the one you turn in, shouldn't do this!