当前位置:网站首页>实例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)结果如下:

边栏推荐
- Shell script basic syntax
- Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
- Why is 1900 not a leap year
- How to copy formatted notepad++ text?
- WiFi wpa_ Detailed description of supplicant hostpad interface
- C WinForm [change the position of the form after running] - Practical Exercise 4
- STM32 single chip microcomputer -- volatile keyword
- Process communication mode between different hosts -- socket
- Some thoughts on extracting perspectives from ealfa and Ebeta
- [paper reading] the latest transfer ability in deep learning: a survey in 2022
猜你喜欢

Carrier period, electrical speed, carrier period variation

UE像素流,来颗“减肥药”吧!

Factors affecting the quality of slip rings in production

Arduino uses nrf24l01+ communication

OC and OD gate circuit

Summary -st2.0 Hall angle estimation

Programming knowledge -- basis of C language

99 multiplication table (C language)

Detailed summary of FIO test hard disk performance parameters and examples (with source code)

STM32 tutorial triple ADC interleaved sampling
随机推荐
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Sql Server的存储过程详解
Bootloader implementation of PIC MCU
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Vofa+ software usage record
Working principle and type selection of common mode inductor
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
leetcode - 445. 两数相加 II
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
99 multiplication table (C language)
Semiconductor devices (I) PN junction
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
Simple design description of MIC circuit of ECM mobile phone
Verilog -- state machine coding method
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
Gradle composite construction
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
STM32---IIC
Consul installation
UE像素流,来颗“减肥药”吧!