当前位置:网站首页>Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
2022-07-05 08:22:00 【Lazy smile】
example 004: The day after that
subject : Enter the date of the year , Judge the day as the day of the year ?
Program analysis : Calculate the day of the year , First of all, we have to calculate the total number of days in the months before this month , Add the date of the month . The sum of days in the previous months , except 2 The month is when the year is leap year 29 God , In ordinary years, it is 28 outer space , The number of days in each month is fixed , So we can set a list of days in a month , When the entered year is a leap year, put it in the list 2 The number of days in the month is changed to 29 God .
# example 004: The day after that
# ** subject :** Enter the date of the year , Judge the day as the day of the year ?
# Used to judge whether the year is a leap year
def isLeapYear(y):
return (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0))
# Definition 1-11 Days of each month
DofM = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
res = 0 # Calculate the day
# Enter the date of the year
year = int(input('Year:'))
month = int(input('Month:'))
day = int(input('day:'))
if isLeapYear(year): # If it's a leap year be 2 Month for 29 God
DofM[2] = 29
for i in range(month): # Calculation month Total previous days
res += DofM[i]
# The day of the year yes month Total previous days + The number of days in this month day
print(res + day)
give the result as follows :
边栏推荐
- C WinForm [display real-time time in the status bar] - practical exercise 1
- Hardware 1 -- relationship between gain and magnification
- Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
- QEMU STM32 vscode debugging environment configuration
- Problem solving: interpreter error: no file or directory
- Tailq of linked list
- 实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
- 【三层架构及JDBC总结】
- Soem EtherCAT source code analysis II (list of known configuration information)
- Arduino uses nrf24l01+ communication
猜你喜欢
Keil use details -- magic wand
Drive LED -- GPIO control
99 multiplication table (C language)
【三层架构及JDBC总结】
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Array integration initialization (C language)
UE像素流,来颗“减肥药”吧!
Semiconductor devices (III) FET
STM32 virtualization environment of QEMU
随机推荐
如何写Cover Letter?
MySQL之MHA高可用集群
C WinForm [exit application] - practice 3
Imx6ull bare metal development learning 2- use C language to light LED indicator
Keil use details -- magic wand
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
STM32---IIC
实例010:给人看的时间
STM32 outputs 1PPS with adjustable phase
QEMU demo makefile analysis
Wifi-802.11 negotiation rate table
Semiconductor devices (I) PN junction
C WinForm [realize the previous and next selection pictures] - practice 7
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Relationship between line voltage and phase voltage, line current and phase current
PMSM dead time compensation
剑指 Offer 06. 从尾到头打印链表
Let's briefly talk about the chips commonly used in mobile phones - OVP chips
MySQL MHA high availability cluster
Circleq of linked list