当前位置:网站首页>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 :
边栏推荐
- Solutions to compilation warnings in Quartus II
- 实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
- After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
- 关于线性稳压器的五个设计细节
- Semiconductor devices (I) PN junction
- OLED 0.96 inch test
- Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
- Tailq of linked list
- C WinForm [get file path -- traverse folder pictures] - practical exercise 6
- STM32 --- NVIC interrupt
猜你喜欢
VESC Benjamin test motor parameters
NTC thermistor application - temperature measurement
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
剑指 Offer 05. 替换空格
leetcode - 445. 两数相加 II
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
C # joint configuration with Halcon
DokuWiki deployment notes
随机推荐
Naming rules for FreeRTOS
Semiconductor devices (III) FET
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
DCDC circuit - function of bootstrap capacitor
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
VESC Benjamin test motor parameters
Detailed explanation of SQL server stored procedures
Array integration initialization (C language)
Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
STM32 --- GPIO configuration & GPIO related library functions
MHA High available Cluster for MySQL
Count the number of inputs (C language)
Explication de la procédure stockée pour SQL Server
Imx6ull bare metal development learning 2- use C language to light LED indicator
Use indent to format code
OC and OD gate circuit
go依赖注入--google开源库wire
Classic application of MOS transistor circuit design (2) - switch circuit design
Relationship between line voltage and phase voltage, line current and phase current