Albion College

CS 171

Introduction to Computer Science I & Lab

Fall 2021

Homework Assignment 1

Background

In this assignment, you will build on skills from Lab 2 and Lab 3 to output calendars for a month or year. This homework assignment is designed to help you master concepts of functions, if statements, and loops.

Don't use any functions from Python's calendar module.

Seek help as soon as you are experiencing difficulty with this assignment.
Do not wait until the deadline to seek help!

Task (25 points total)

Abbreviated Day Name (5 points)

Create a function based on your dayName2 function from Lab 2 that produces an two character abbreviated day name (Sa, Su, Mo, Tu, We, Th, Fr).

Month (15 points)

Write a function printMonth(month,year) that prints a grid formatted month starting with Sunday. Below are examples for September 2021 and February 2020.


     September
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

               

      February
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

Print the name of the month centered in a string having a width of 20.

Label each column with an abbreviated day name using your function above. Use a loop with a call to your abbreviated day name function.

Print the days. Use a standard grid with each day of the month printed right justified in a field with of 2 and separated by a single space.

Use your day function from Lab 2 to determine the starting day of the week for the first day of the given month and year. Recall the day function returns 0 for Saturday and 6 for Friday. Print spaces for each of the days preceding the starting day using a loop.

Determine the number of days in the month using the daysInMonth function you created in Lab 2. Loop over every day in the month, printing that number in the appropriate place.

When month is 9 and year is 2021, you program should output the calendar above.

Year (5 points)

Create a function printYear(year) that prints the month calendars for every month of the year by looping over every month in the given year. Print a blank line after each month.

Stub code

# HW 1 - Your name and email here # your functions here def main(): printMonth(2,2020) printMonth(9,2021) printYear(2020) # leap year printYear(2021) # non-leap year # other test cases # consider printing the calendar for the year you were born # or other important years main()

Deliverables

Send me (dreimann@albion.edu) your Python .py file as an attachment to an email message with Homework 1 as the subject line.