Advertisement
big_cee223

python leap years check -- Oum

Apr 18th, 2022
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # Python program to check if year is a leap year or not
  2.  
  3. year = int(input("Enter a Year : "))
  4.  
  5. # To get year (integer input) from the user
  6. # year = int(input("Enter a year: "))
  7.  
  8. # divided by 100 means century year (ending with 00)
  9. # century year divided by 400 is leap year
  10. if (year % 400 == 0) and (year % 100 == 0):
  11.     print("{0} is a leap year".format(year))
  12.  
  13. # not divided by 100 means not a century year
  14. # year divided by 4 is a leap year
  15. elif (year % 4 ==0) and (year % 100 != 0):
  16.     print("{0} is a leap year".format(year))
  17.  
  18. # if not divided by both 400 (century year) and 4 (not century year)
  19. # year is not leap year
  20. else:
  21.     print("{0} is not a leap year".format(year))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement