TORONTO KIDS COMPUTER CLUB | Wednesday Friday 15:00 Python Practice 20.08.21.
18180
post-template-default,single,single-post,postid-18180,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Wednesday Friday 15:00 Python Practice 20.08.21.

25 Aug Wednesday Friday 15:00 Python Practice 20.08.21.

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]

1Comment
  • Jesse
    Posted at 17:10h, 26 August Reply

    year = int(input(‘year: ‘))
    month = int(input(‘month: ‘))
    day = int(input(‘day: ‘))
    if year % 4 == int:
    diy = days in year
    dim = days in month
    diy = 366
    year = ‘leap’
    if year % 4 == float:
    diy = 365
    year = ‘unleap’
    if month == (‘2’) and year == ‘leap’:
    dim = 28
    if month == (‘2’) and year == ‘unleap’:
    dim = 29
    if month == (‘1’ or ‘3’ or ‘5’ or ‘7’ or ‘8’ or ’10’ or ’12’):
    dim = 31
    if month == (‘4’ or ‘6’ or ‘9’ or ’11’):
    dim = 30
    dim * month + day = num:
    print(‘This is the’, num,’day of the year)

Post A Comment