Your instructor may assign one or more of the following problems. Don’t feel that you must do all the problems; for the homeworks, you are only required to do those that are explicitly assigned via Moodle.

  1. Write a program called circles.py that prompts the user to enter the center coordinates and radii of two circles. Both circles should be drawn using turtle graphics. Further, your program should determine if the second circle is inside the first or overlaps with the first and write an appropriate description to the canvas. Notes:
  2. Write a program called rectangles.py that works as described in the previous homework exercise except that it specifies two rectangles, each via the coordinates of the rectangle’s top left corner, the rectangle’s width and its height, and then indicates whether or not the rectangles overlap.

    Note that this version of the homework does not need to indicate whether one rectangle contains the other. Only the overlap/non-overlap needs to be determined.

  3. Write a program called daycomputer.py that asks the user for 3 values: month, day, and year. All values should be converted to and stored as integers.

    The code first calculates if the year is a leap year, storing the result in a boolean variable. A year is a leap year if it is divisible by 4, unless it is a century year that is not divisible by 400. (1800 and 1900 are not leap years while 1600 and 2000 are.) Print out whether the year is a leap year or not, before going on.

    Now, add to the program to check if the given values represent a legal date. For example, February 30 is not legal, and February 29 is not legal unless it is a leap year. July 44 is never legal. Print out whether or not the entered values represent a legal date.

    Finally, if the date is legal, your program needs to calculate the day number for a given date. January 1 is day number 1, January 2 is day number 2, etc., and December 31 is day number 365 (or 366 for a leap year). The day number can be computed in three steps, using integer arithmetic.

    1. dayNum = 31(month - 1) + day
    2. if the month is after February subtract (4*month + 23) / 10
    3. if it is a leap year and after Febrary 29, add 1

    Print out the day number in a nice formatted string: e.g.,
    The date 1/1/1987 has day number 1.

    Here is an example of a run of my code:

    Mac52078:~/classes/cs108/sample_code vtn2$ python3 daycomputer.py
    Enter a month number: 3
    Enter a day: 22
    Enter a year: 1988
    1988 is a leap year.
    3/22/1988 is a legal date.
    The date 3/22/1988 has day number 82.

    Here is another example:

    Mac52078:~/classes/cs108/sample_code vtn2$ python3 daycomputer.py
    Enter a month number: 7
    Enter a day: 44
    Enter a year: 1988
    1988 is a leap year.
    7/44/1988 is not a legal date.

Checking In

We will grade this assignment according to the following criteria: