当前位置:网站首页>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 :
边栏推荐
- Halcon's practice based on shape template matching [2]
- MySQL之MHA高可用集群
- FIO测试硬盘性能参数和实例详细总结(附源码)
- Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
- [trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
- Sizeof (function name) =?
- Brief discussion on Buck buck circuit
- Array integration initialization (C language)
- QEMU demo makefile analysis
- My-basic application 1: introduction to my-basic parser
猜你喜欢
Design a clock frequency division circuit that can be switched arbitrarily
Keil use details -- magic wand
实例008:九九乘法表
Halcon's practice based on shape template matching [1]
Arduino uses nrf24l01+ communication
UE像素流,来颗“减肥药”吧!
Circleq of linked list
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
Array integration initialization (C language)
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
随机推荐
剑指 Offer 05. 替换空格
Stablq of linked list
Array integration initialization (C language)
Drive LED -- GPIO control
Imx6ull bare metal development learning 2- use C language to light LED indicator
Summary of SIM card circuit knowledge
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Basic embedded concepts
Various types of questions judged by prime numbers within 100 (C language)
如何写Cover Letter?
Bluetooth hc-05 pairing process and precautions
Let's briefly talk about the chips commonly used in mobile phones - OVP chips
动力电池UL2580测试项目包括哪些
实例007:copy 将一个列表的数据复制到另一个列表中。
Verilog -- state machine coding method
Halcon's practice based on shape template matching [2]
Arduino uses nrf24l01+ communication
剑指 Offer 06. 从尾到头打印链表
Bootloader implementation of PIC MCU
STM32 virtualization environment of QEMU