current position:Home>Python, C problem - leap year judgment

Python, C problem - leap year judgment

2022-02-02 23:48:31 CSDN Q & A

As shown in the figure :
Judge whether there is this date in leap year , Have output 1, No, , Output -1, How to write code ?

img




Refer to the answer 1:

Judgement of leap year :

data3 = pd.DataFrame(pd.date_range("2011-01-01","2021-01-01", freq="Y"),columns=["years"])data3['leap'] = data3['years'].dt.is_leap_year



Refer to the answer 2:



Refer to the answer 3:

from datetime import datetime

cur_date = datetime.now().strftime('%Y-%m-%d').split('-')

cur_date = input(' Please enter the date to calculate , example :2021-3-5:').split('-')
print(cur_date) # 2021-3-5
cur_year = int(cur_date[0])
cur_month = int(cur_date[1])
cur_day = int(cur_date[2])

month_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if cur_year % 400 == 0 or (cur_year % 4 == 0 and cur_year % 100 != 0):
month_day[1] = 29
if cur_month == 1:
days = cur_day
else:
days = -1 #sum(month_day[0:cur_month - 1]) + cur_day

print(days)




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022348300814.html

Random recommended