Home CPSC 110

Lab 8: Day of Week Calculator

 

Objective

To gain experience using standard library functions


 

Task

For this lab, you will write a program that tells someone what day of the week a given date is. For example, your program will be able to tell us that October 31, 2024 will fall on a Thursday or that January 1, 1731 was a Monday.

This would be a very hard problem to solve ourselves, but will be made much easier by using the calendar library that comes with Python.

The function from this library we want is called weekday and does just what we want.


 

Details

  1. Start by importing the calendar library.
  2. Start by asking the user to enter three numbers, the month, day and year.
  3. Next call the weekday function, passing in these three values. Note the order that it takes in the three values.
  4. This function returns back to us a number representing the day of the week. 0 is returned for Monday, 1 for Tuesday, 2, for Wednesday and so on. Day 6 is Sunday.
  5. Based on this number, make a chain of if/elif statements to print out the day of the week for the day that was given in.

 

Example Run

Below is an example run of how this program should work:

Month: 10
Day: 26
Year: 1984
10/26/1984 is a Friday.

 

Submitting

When you are finished, please submit the .py file for the lab on Canvas. To do so, you'll need to navigate to where you saved the file on your computer.

Copyright © 2024 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.