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)