Use Python to write a leap year calculator and a monthly days calculator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.