-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhich_day.py
More file actions
40 lines (31 loc) · 1000 Bytes
/
which_day.py
File metadata and controls
40 lines (31 loc) · 1000 Bytes
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
32
33
34
35
36
37
38
39
40
#函数用于计算指定的年月日是这一年的第几天
def is_leap_year(year):
"""
判断指定的年份是不是闰年
:param year: 年份
:return: 闰年返回True平年返回False
"""
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
def which_day(year, month, date):
"""
计算传入的日期是这一年的第几天
:param year: 年
:param month: 月
:param date: 日
:return: 第几天
"""
days_of_month = [
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
][is_leap_year(year)]
total = 0
for index in range(month - 1):
total += days_of_month[index]
return total + date
def main():
year=int(input('请输入年:'))
month=int(input('请输入月份:'))
date=int(input('请输入日期:'))
print(which_day(year,month,date))
if __name__ == '__main__':
main()