TORONTO KIDS COMPUTER CLUB | Friday Python Practice 20:30 – 22.10.07
21220

# Friday Python Practice 20:30 – 22.10.07

## 12 Oct Friday Python Practice 20:30 – 22.10.07

Question:
write a program to ask user about the date(year, month and day), then calculate the day of the year.

Sample input：

Year: 2016
Month: 6
Day: 23

Sample output：

Day of the year: 175

Hint:

• You need consider leap years and non leap years, in order to do easier calculation, you may create a list to contain all the days in each month. If it is a leap year, then mo = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], otherwise, mo = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
• % is getting remainder of the division, so we can use it to calculate the leap year or not, for example year 2016 is a leap year because 2016 % 4 == 0
• We could use for i in range() to get the index of every previous month and add them together. Or we could use sum(list) to calculate the total number in the list or slice of the list, for example: if there’s a list a = [1,2,3,4,5,6,7], then sum(a[:5]) will add 1,2,3,4,5 together