Analyzing small example of a leap year python3

I. Method 1:

. 1  the while True:
 2      the try :
 . 3          year = int (INPUT ( ' Enter a year: ' ))
 . 4          IF (% year. 4) == 0 and (100% year) = 0! Or (year 400%) == 0:
 . 5              Print ( ' {0} is a leap year. ' .format (year))
 . 6          the else :
 . 7              Print ( ' . {0} is not a leap year ' .format (year))
 . 8          BREAK 
. 9      the except a ValueError:
 10          Print ( 'The year you entered is not recognized, please enter the correct year (integer). ' )

Second, Method 2:

. 1  the while True:
 2      the try :
 . 3          year = int (INPUT ( ' Enter a year: ' ))
 . 4          IF (% year. 4) == 0:
 . 5              IF (100% year) == 0:
 . 6                  IF (year% 400) == 0:
 . 7                      Print ( ' {0} is a leap year ' .format (year))     # whole hundred divisible by 400 is a leap year 
. 8                  the else :
 . 9                      Print ( ' {0} is not a leap year ' .format (year) )
 10              the else :
 11                  Print( ' {0} is a leap year ' .format (year))   # non-integer divisible by four hundred leap year is 
12 is          the else :
 13 is              Print ( ' {0} is not a leap year ' .format (year))
 14  
15      the except a ValueError:
 16          Print ( ' the year you entered is not recognized, please enter the correct year (integer). ' )

Third, the method 3: Internal function calls

. 1  Import Calendar
 2  the while True:
 . 3      the try :
 . 4          year = int (INPUT ( ' Enter a year: ' ))
 . 5          check_year = calendar.isleap (year)
 . 6          IF check_year:
 . 7              Print ( ' {0} is a leap year ' . the format (year))
 . 8          the else :
 . 9              Print ( ' {0} is not a leap year ' .format (year))
 10          BREAK 
. 11      the except a ValueError:
 12 is          Print (' Year you entered is not recognized, please enter the correct year (integer). ' )

 

Guess you like

Origin www.cnblogs.com/gengyufei/p/11328436.html