[Python] [8] [demo experimental practice examples] [calculated that day is the first few days of the year]

Title: Enter a certain period of a day, this day is judgment day of the year?

Program analysis:

To March 5, for example, we should put the first two months together, then add the five days that is the day of this year's special circumstances, leap year and added an extra day to consider the input when the month is greater than 2:

For years, the need to consider whether a leap year;

For the month, you can create a list of the number of days each month;

 

My source code:

  

# ! / Usr / bin / Python 
# encoding = UTF-8 
# - * - Coding: UTF-8 - * - 

# Title: enter a certain day in a certain month, this day is judgment day of the year? 


DATE = (INPUT ( " Please The INPUT DATE: \ n- " ))
 # Input format is 20,190,909 
pingNian = [0,31,28,31,30,31,30,31,31,30,31,30,31] # -average number of days per month 
runNian = [0,31,28,31,30,31,30,31,31,30,31,30,31] # leap month days 
y = int (date [0: 4]) # Get Year 
m = int (dATE [. 4:. 6]) # Gets month 
D = int (dATE [. 6:. 8]) # Gets days 
NUM = 0     # statistics for 
K = 0     #Leap year leap year or for marking, k == 1 indicates a leap year; 



# RUN function determines whether or not a leap year 
# divisible by 4 is not divisible by 100 are leap 
# divisible by 400 is a leap year; 



# Print (pingNian , runNian, Y, m, D, NUM, K) 

DEF RUN (Y): 

    return (Y == 0. 4% and ! 100 = 0% Y or Y 400% == 0) 







IF m in [1,2 ] :
     IF m == 2 : 
        NUM = pingNian [. 1] + D
     the else : 
        NUM = D
 the else :
     IF RUN (Y):
         for I in Range (. 1 , m):
            whether num + runNian [i]
             print ( " * " , num)
     else :
         for i in range (1 m): 
            whether num + pingNian [i]
             print ( " # " , num) 
    whether num + d
 Print (num)

 

 

Output:

C:\Python30_demo>python 019demo.py
please input the date:
20130506
# 31
# 59
# 90
# 120
126

 

 

The original title given answers:

 

 

 

 

 

 

-------- (I am dividing line) --------

reference:

1. RUNOOB.COM  : https://www.runoob.com/python/python-exercise-example3.html

2. https://zhidao.baidu.com/question/467715860.html

3. Baidu Encyclopedia: https://baike.baidu.com/item/%E5%AE%8C%E5%85%A8%E5%B9%B3%E6%96%B9%E6%95%B0/8025061? fr = aladdin

 

Remarks:

Initial modified: September 23, 2019 23:10:11

 

Environment: Windows 7 / Python 3.7.2

 

Guess you like

Origin www.cnblogs.com/kaixin2018/p/11575578.html