Leap Year Calculator
Title: Enter the year to determine if the year is a leap years.
Method: 1. Year that can be divisible by 400
2. Can be divisible by 4, but not divisible by 100
1 Print('---Leap year judgment kql, press Q to exit---')2 whileTrue:3y = input ('Please enter the year:')4 if(Y = ='Q'):5 Break6y =Int (y)7 if(y% 400 = = 0or(y% 4 = = 0 andY% 100! =0)):8 Print(Y,'year for leap years! ')9 Else:Ten Print(Y,'year for common year! ') One #Python Learning Group 125240963
Note: The above case mainly involves the condition judgment if...else ... And the knowledge points of the relational operators.
Monthly Days Calculator
Title: Enter a month to determine how many days the month
Method: First determine whether the year is a leap or common year, and then calculate the number of days to enter the month under that year
1 Print('---Calculator that displays the number of days in the month----')2y = input ('Please enter the year:')3y =Int (y)4m = input ('Please enter the month:')5m =Int (m)6Rnd = [0,31,29,31,30,31,30,31,31,30,31,30,31]#leap year days per month7PND = [0,31,28,31,30,31,30,31,31,30,31,30,31]#leap year days per month8 #since the first bit of the list is 0, it is defined from the beginning9Day =0Ten if(y% 400 = = 0or(y% 4 = = 0 andY% 100! =0)): OneDay =Rnd[m] A Else: -Day =Pnd[m] - the Print('the number of days for this under decade month is (days):', day)
Note: The second case, although similar to the first one, is added to the list.
Use Python to write a leap year calculator and a monthly days calculator