year = int(input("Enter a year: "))
if not ((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)):
print("The year is NOT a leap year.")
else:
print("The year is a leap year.")
#source code --> clcoding.com
Code Explanation:
Taking User Input
year = int(input("Enter a year: "))
The user enters a year, which is stored in the variable year.
Since input() returns a string, we convert it to an integer using int().
Checking if the Year is NOT a Leap Year
if not ((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)):
Step 1: Check if the year is a leap year using two conditions:
(year % 4 == 0 and year % 100 != 0):
The year must be divisible by 4 and NOT divisible by 100 (e.g., 2024).
(year % 400 == 0):
The year must be divisible by 400 (e.g., 2000).
Step 2: Use not to check if the year is NOT a leap year
If the year does NOT satisfy either of the above conditions, then it is NOT a leap year.
Printing the Result
print("The year is NOT a leap year.")
If the not condition is True, the year is NOT a leap year.
else:
print("The year is a leap year.")
Otherwise, the year is a leap year.
0 Comments:
Post a Comment