Skip to main content

Exercises 8.14 Drill and Practice

3.

Write a program that takes an exam mark and determines the corresponding letter grade using the scale below.
Table 8.14.1.
Mark Grade
>= 90 A
[80-90] B
[70-80] C
[60-70] D
< 60 F
Pay close attention to the boundary values. For example:
Your program should print both the mark and the grade.
Test your program with several different marks, including values near the grade boundaries.

4.

Write code that takes an integer and prints True if the integer is an even number and False if it is odd.

5.

Implement the calculator for the date of Easter.
The following algorithm computes the date for Easter Sunday for any year between 1900 to 2099.
Ask the user to enter a year. Compute the following:
  1. a = year % 19
  2. b = year % 4
  3. c = year % 7
  4. d = (19 * a + 24) % 30
  5. e = (2 * b + 4 * c + 6 * d + 5) % 7
  6. dateofeaster = 22 + d + e
Special note: The algorithm can give a date in April. Also, if the year is one of four special years (1954, 1981, 2049, or 2076) then subtract 7 from the date.
Your program should print an error message if the user provides a date that is out of range.
Solution.
year = int(input("Please enter a year"))
if year >= 1900 and year <= 2099:
    a = year % 19
    b = year % 4
    c = year % 7
    d = (19*a + 24) % 30
    e = (2*b + 4*c + 6*d + 5) % 7
    dateofeaster = 22 + d + e

    if year == 1954 or year == 2981 or year == 2049 or year == 2076:
        dateofeaster = dateofeaster - 7

    if dateofeaster > 31:
        print("April", dateofeaster - 31)
    else:
        print("March", dateofeaster)
else:
    print("ERROR...year out of range")
You have attempted of activities on this page.