Length of a month design a function that takes two


Must be written in Python 3.5

Cannot use the canned draw_calender function or will receive a zero

The assignment is to create a nicely formatted calendar for any month of any year. 

  1. Length of a Month Design a function that takes two parameters: year and month, and returns an integer indicating how many days long that month is. January 2009 was 31 days long, February 2009 was 28 days long, February 2008 was 29 days long, and so on. Remember that for February, leap years must be taken into account. For this first part, we are only interested in the 21st century. Between the years 2000 and 2099 the leap year rule is very simple: a year is a leap year if it is divisible by four. Incorporate your function into a simple program that allows you to test it conveniently, and then test it conveniently. Each stage of this lab assignment depends on the previous stage, so you won't do any good by going ahead with an incorrect function. 
  2. Day of the Year. Design a function that takes three parameters: year, month, and day, and returns an integer indicating which day of the year that date is. For example, the 1st of January is day 1 of the year, the 2nd of January is day 2, the 1st of February is day 32, and so on. Incorporate your function into a simple program that allows you to test it conveniently, and then test it thoroughly. 
  3. Day of the Century. Now make a function that tells you what day of the century it is. Forget about foolish arguments about whether the century starts in 2000 or 2001. If you take 1st January 2000 as day 1, everything works out nicely. So 31st December 2000 was day 366, and 1st January 2001 was day 367, and so on. You still only need to be concerned with this century, 2000 to 2099.
  4. Day of Forever. You knew this part was coming. Now we want a function that again takes three parameters, representing year, month, and day, but this time, the year could be any positive number. This raises two issues: where to start counting (i.e. what date shall we choose to be day number 1?), and how to handle leap years. Although pedantic folk will argue that there is no such thing as the year 0, pretending that there was makes for a very simple solution. Day 1 will be 1st January of the year 0 regardless of whether or not that date ever existed. It makes the counting easy. The true rules for leap years are slightly more complex than just divisibility by four. The exact rules are given on the last page if you don't already know them, but in summary: Any year that is divisible by 400 is a leap year, any other year that is divisible by 100 is not a leap year, any other year that is divisible by 4 is a leap year, and any other year is not a leap year. Here are some pre-calculated samples to help with testing: 1st January 2000 was day number 730486 4th July 1776 was day number 648857 2nd, 3rd, and 4th of October 2012 are days 735144, 735145, and 735146 27th November 2737 will be the millionth day 1st January of the year 10 A.D. was day 3654 Give some serious thought to testing. If you are getting the wrong number for a date, try some very close dates, and you are likely to spot a pattern in the error that will give you a big clue about where your program may be wrong. 
  5. Day of the Week. Now make a function that takes year, month, and day as parameters, and tells you what day of the week that date was. In some strange and wild countries, such as Czechoslovakia, the week starts on a Monday. We'll keep them happy. Make your function return the answer as an int, using 0 for Monday, 1 for Tuesday, ..., and 6 for Sunday. This is very easy if you think of the modulo % operator and remember how many days there are in a week. Also, make it flexible so that you could start the calendar on any day and you could then sell it in any strange and wild countries. 
  6. A Calendar for a Month. Use that function in a program that allows the user to enter two integers, representing year and month, and then prints a correctly formatted calendar for that day and month. Like this, which would come from an input of 2014 2: Mo Tu We Th Fr Sa Su 12 3456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

You certainly know how to print out a list of numbers starting from 1. To make those numbers come out looking like a calendar, you need to work out how many spaces to print before the "1", and how to tell when it is time to start a new line. You also need to take a little care to get the alignment of one and two digit numbers right. 

  1. A solid Product. Make sure that your calendar works for any year, not just in the 21st Century, And enable the user to print a calendar that starts on any day not just Monday. 
  2. Write a function that works out how many sundays any given year has.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Length of a month design a function that takes two
Reference No:- TGS01480827

Now Priced at $30 (50% Discount)

Recommended (95%)

Rated (4.7/5)