You are on page 1of 1

School of Computing and Informatics

|BCS 111 | CAT | Date: Mon 16-11-2021 |Time 1:00 - 4:00| 30 MARKS |

A week as 7 days, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. Monday has
index 0, Tuesday has index 1. . . . . . till Sunday has index 6. The index of the day on which 1st of January
falls is given by the formula

i = R(5((year − 1), 4) + 4((year − 1), 100) + 6((year − 1), 400), 7)

where R(x,y) is a function that returns remainder after dividing x by y.

Consider a Python program with following first lines


1 daysPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
2 days = [’Monday’, ’Tuesday’, ’Wednesday’, ’Thursday’, ’Friday’,’Saturday’, ’Sunday’]
3 months = ["January", "February", "March", "April", "May", "June", "July", "August", "
September", "October", "November", "December"]

(a) Write a function firstJan which receives a year and returns the index of the day on which first of
January fall [3 Marks]

(b) Write a function isLeap which receives a year and change number of days of February to 29 if the
year received is a leap year. A leap year is divisible by 4 [4 Marks]

(c) Write a function birthDays which receives year, month and day, then displays the day on which your
birthday falls. If you were born on 12-April and you pass the values 12, 4, 2021 to this function, it
should display Your birth day in 2021 is on a Monday 12/April/2021. Re-use the functions in (a) and
(b) above [8 Marks]

(d) Write a function that receives the month and year you were born, and displays the calendar for the
previous month in a 6 by 7 grid. If you were born in September, and you enter year as 2021, your
function should display the output below

Example Output

August 2021
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 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 1 2 3 4 5

[12 Marks]

(e) Write main function and invoke the functions in (a), (c) and (d). Read day, month and year as
integers and pass them appropriately to these functions [3 Marks]

2021 BCS 360 CAT, SCI, MMUST, Main. Examiner: Dr. R. Angulu 1

You might also like