当前位置:网站首页>实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
2022-07-05 08:16:00 【懒笑翻】
实例004:这天第几天
题目:输入某年某月某日,判断这一天是这一年的第几天?
程序分析:计算这一天是该年的第几天,我们首先要计算出这个月之前那几个月总共有多少天,再加上该月的日期。前面几个月的天数求和中,除了2月份在年份为闰年的时候为29天,平年的时候为28天外,每个月的天数都是固定的,因此我们可以先设定一个月份天数的列表,当输入的年份是闰年时再把列表中2月的天数改为29天。
# 实例004:这天第几天
# **题目:**输入某年某月某日,判断这一天是这一年的第几天?
# 用于判断该年是否是闰年
def isLeapYear(y):
return (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0))
# 定义1-11月每个月的天数
DofM = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
res = 0 #计算第几天
# 输入某年某月某日
year = int(input('Year:'))
month = int(input('Month:'))
day = int(input('day:'))
if isLeapYear(year): # 如果是闰年 则2月为29天
DofM[2] = 29
for i in range(month): # 计算month之前的总天数
res += DofM[i]
# 这一年的第几天 是 month之前的总天数+这个月的天数day
print(res + day)
结果如下:
边栏推荐
- Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
- STM32 virtualization environment of QEMU
- Sql Server的存储过程详解
- Briefly talk about the identification protocol of mobile port -bc1.2
- Soem EtherCAT source code analysis II (list of known configuration information)
- C WinForm [exit application] - practice 3
- My-basic application 2: my-basic installation and operation
- UEFI development learning 6 - creation of protocol
- Arduino uses nrf24l01+ communication
- Zero length array in GNU C
猜你喜欢
PMSM dead time compensation
Nb-iot technical summary
Management and use of DokuWiki (supplementary)
Reasons for rapid wear of conductive slip rings
H264 (I) i/p/b frame gop/idr/ and other parameters
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
STM32 single chip microcomputer - bit band operation
UEFI development learning 6 - creation of protocol
Process communication mode between different hosts -- socket
NTC thermistor application - temperature measurement
随机推荐
Shell script basic syntax
Network communication model -- Network OSI tcp/ip layering
Live555 push RTSP audio and video stream summary (I) cross compilation
FIO测试硬盘性能参数和实例详细总结(附源码)
Simple design description of MIC circuit of ECM mobile phone
Connection mode - bridge and net
go依赖注入--google开源库wire
Synchronization of QT multithreading
STM32 --- configuration of external interrupt
Brief discussion on Buck buck circuit
Development tools -- gcc compiler usage
OC and OD gate circuit
STM32 single chip microcomputer - external interrupt
My-basic application 2: my-basic installation and operation
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
Semiconductor devices (I) PN junction
Keil use details -- magic wand
Bluetooth hc-05 pairing process and precautions
Wifi-802.11 negotiation rate table
Verilog -- state machine coding method