Little Turtle Python Video V (after-school exercises)

Source: Internet
Author: User

1. Leap year (need to be optimized, can only be cycled once)

year = Int (input ("Please enter the number of years:"))ifYear% 4:    Print("not a leap year")#It can't be divisible by 4.Else:    ifYear% 400:        ifYear% 100:            Print("Leap Year")#That can be divisible by 4, but not divisible by 100.        Else:            Print("not a leap year")#Divisible by 4 and divisible by 100, but not evenly divisible .    Else:        Print("Leap Year")#Divisible by 4 can be divisible by 400.    

Elementary Turtle's Code:

temp = input ('Please enter a year:') while  nottemp.isdigit (): Temp= Input ("Sorry, your input is wrong, please enter an integer:") Year=Int (temp)ifyear/400 = = Int (year/400):    Print(temp +'is a leap year! ')Else:    if(YEAR/4 = = Int (YEAR/4)) and(year/100! = Int (year/100)):        Print(temp +'is a leap year! ')    Else:        Print(temp +'not a leap year! ')

Little Turtle Python Video V (after-school exercises)

Related Article

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.