1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | def is_leap_year(year): # If year is divisible by 4 if year % 4 == 0: # If year is also divisible by 100 if year % 100 == 0: # If year is divisible by 400, it's a leap year if year % 400 == 0: return True # Divisible by 100 but not by 400, not a leap year else: return False # Divisible by 4 but not by 100, it's a leap year else: return True # Not divisible by 4, not a leap year else: return False # Input from the user year = int(input("Enter a year: ")) # Check if the year is a leap year if is_leap_year(year): print(f"{year} is a leap year.") else: print(f"{year} is not a leap year.") | cs |
Á¶°ÇÀ» °£´ÜÇÏ°Ô ÇÑ ÁٷΠǥÇö
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def is_leap_year(year): if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: return True else: return False # Input from the user year = int(input("Enter a year: ")) # Check if the year is a leap year if is_leap_year(year): print(f"{year} is a leap year.") else: print(f"{year} is not a leap year.") | cs |