> cal 1 2024 January 2025 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 > 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 30I'll bet you didn't realize there was a month with only 19 days! (That's when the Julian calendar was replaced by the Gregorian calendar in Britain and its colonies, including the U.S.)
There's even a built in calendar app within Python:
>>> import calendar >>> print( calendar.month(2025, 2) ) February 2025 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 >>>In this project, you'll be building your own calendar app, but one much simpler than those. You app need only work for the months in the year 2025. The user of your application will enter a positive integer in the range [1..12], indicating the month. In response, you'll print the calendar for that month in 2025. This functionality is embedded within a loop so that the user can ask for calendars for a series of months. Exit the loop when the user enters 0.
Here are some samples:
> python Project1.py Welcome to our calendar utility! Print the calendar for any month in 2025. Enter a month [1..12] or 0 to stop: 0 Thanks for visiting! Goodbye! > python Project1.py Welcome to our calendar utility! Print the calendar for any month in 2025. Enter a month [1..12] or 0 to stop: -12 Month must be a number between 1 and 12, or 0 to stop. Try again. Enter a month [1..12] or 0 to stop: 17 Month must be a number between 1 and 12, or 0 to stop. Try again. Enter a month [1..12] or 0 to stop: abd Month must be a number between 1 and 12, or 0 to stop. Try again. Enter a month [1..12] or 0 to stop: 1 January, 2025 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 Enter a month [1..12] or 0 to stop: 2 February, 2025 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 Enter a month [1..12] or 0 to stop: 3 March, 2025 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 Enter a month [1..12] or 0 to stop: 12 December, 2025 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 Enter a month [1..12] or 0 to stop: 0 Thanks for visiting! Goodbye! >That's it. Note that one way to accomplish this would be to write separate code for each month and just print it out, as you did with your initials in HW1. That is not allowed. You have to compute and print each calendar using the algorithm outlined below.
Here are some hints and requirements:
# Some symbolic constants it would be useful to define: SUN = 0 MON = 1 ... SAT = 6 JAN = 1 FEB = 2 ... DEC = 12 def monthName( n ): """Given the number of a month, return its name. Assume that n is in range [1..12]. Example, if n == JAN (i.e., 1), return 'January'. """ pass def firstDayOfMonth( n ): """Given a month in 2025, on which day (number) does it begin. Example, if n == JAN, return WED (i.e, 3), since January, 2025 begins on Wednesday (day 3). It's best to number the days from [0..6]. This helps because, if the month begins on FRI = 5, you'll need to start the first line of numbers with 5 * 3 blanks. """ pass def daysInMonth2025( n ): """Given a month in 2025, how many days are in it? For example, given n == JAN (i.e., 1), return 31 since there are 31 days in January of 2025. You can obtain this information by looking at a calendar for 2025, or just use your knowledge of how many days are in each month. 2025 is not a leap year. """ pass def printCalendarMonth( n ): """Print the calendar for the month n for 2025 where n is in range [1..12]. For example, printCalendarMonth(1) should display: January, 2025 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 """ pass def main(): """Run a loop accepting from the user month numbers. Print the calendar for each month requested from 2025. Stop when the user enters 0. Validate user input and allow multiple tries if the user enters invalid inputs. """ passBTW: you don't have to validate the input for any of the functions. That is done inside main(); you should never call any of the other functions except on data that is known to be legal.
Your file must compile and run before submission. It must also contain a header with the following format:
# File: Project1.py # Student: # UT EID: # Course Name: CS303E # # Date Created: # Description of Program:
>>> from Project1 import * >>> monthName( 7 ) 'July' >>> firstDayOfMonth( 10 ) 3 >>> daysInMonth2025( 2 ) 28 >>> printCalendarMonth( 8 ) August, 2025 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 >>>Using Symbolic Constants: In this program, we're "encoding" months as numbers [1..12] and days of the week as numbers [0..6]. That might not immediately be obvious to someone reading your code. This is a great example when symbolic constants are useful. By convention, the names of symbolic constants should be in all capital letters.
For example, instead of using the numbers [1..12] to refer to the months of the year, we might define the number associated with each month as a symbolic constant. These are defined outside of any function, preferably near the top of your file.
JAN = 1 FEB = 2 ... DEC = 12Then, any reference to 2, say, that refers to February will instead be FEB in your code. This makes your program much more readible and maintainable. For example, to see whether the month entered is legal, you might have code containing the condition:
if JAN <= month <= DEC: ...And when computing the first day of a month in 2025 you might have have a clause such as:
elif month == OCT: return WEDNow, isn't that more readible than:
elif month == 10: return 3But notice that the Python assignment
JAN = 1is really just defining a variable, not a constant. There's nothing to prevent you from assigning JAN a different value within your program. (But you'd be nuts to do that.) Treat it as a symbolic constant even though there's nothing in Python (unlike some other programming languages) that really guarantees that it remains constant.
Another great use is to give a symbolic name to a numeric constant that appears frequently in your code, but which never changes within your program:
INTEREST_RATE = 8.5In addition to making your code easier to read, it makes it simple to update your program if the value of this constant changes. Otherwise, you'd have to comb through your entire program to find every occurrence of 8.5 (and make sure that that is actually referencing the interest rate).
BTW: Many students get confused when defining symbolic constants. Remember JAN and SUN are just the names of variables that contain numbers; they're not strings. So, you wouldn't say:
if "JAN" <= month <= "DEC":That would give you a type error; you'd be comparing numbers and strings.