Luogu question writing Python language | P5716 Days in the month

Learn Python from a young age! Record the questions in the Luogu Python learning and exam preparation process, and record every moment.

Attached is a summary post: Luogu’s Python language | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

Input the year and month, and output the number of days in this month of the year. Leap years need to be taken into account.

【enter】

Enter two positive integers, representing the year y y  and the month m m respectively , separated by spaces.

【Output】

Output a line with a positive integer indicating how many days there are in this month.

【Input sample】

1926 8

【Output sample】

31

[Detailed code explanation]

y,m = [int(i) for i in input().split()]  
if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12: 
    day = 31
elif m == 4 or m == 6 or m == 9 or m == 11: 
    day =30
elif m == 2:
    if y%4==0 and y%100!=0 or y%400==0:
        day = 29
    else:
        day = 28  
print(day)

【operation result】

1926 8
31

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132777932