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

边栏推荐
- Network port usage
- Semiconductor devices (III) FET
- C WinForm [change the position of the form after running] - Practical Exercise 4
- Volatile of C language
- VESC Benjamin test motor parameters
- Shell script basic syntax
- Nb-iot technical summary
- 动力电池UL2580测试项目包括哪些
- 亿学学堂给的证券账户安不安全?哪里可以开户
- Programming knowledge -- assembly knowledge
猜你喜欢

My-basic application 2: my-basic installation and operation

Charge pump boost principle - this article will give you a simple understanding

Connection mode - bridge and net

Class of color image processing based on Halcon learning_ ndim_ norm. hdev

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

Design a clock frequency division circuit that can be switched arbitrarily

VESC Benjamin test motor parameters

Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!

Briefly talk about the identification protocol of mobile port -bc1.2

Negative pressure generation of buck-boost circuit
随机推荐
Various types of questions judged by prime numbers within 100 (C language)
动力电池UL2580测试项目包括哪些
DokuWiki deployment notes
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
Shell script realizes the reading of serial port and the parsing of message
STM32 --- NVIC interrupt
1-stm32 operation environment construction
Fundamentals of C language
Hardware and software solution of FPGA key chattering elimination
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
C language enhancement -- pointer
List of linked lists
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
leetcode - 445. 两数相加 II
Sizeof (function name) =?
Detailed explanation of SQL server stored procedures
Void* C is a carrier for realizing polymorphism
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Stm32--- systick timer
Measurement fitting based on Halcon learning [i] fuse Hdev routine