Check if a year is a leap year in Python

Day 15/30 🔹 Problem: Check if a year is a leap year 🔹 What I focused on today: Understanding how multiple conditions work together 🔹 My Thinking Process: A year is divisible by 4 → leap year But if divisible by 100 → NOT a leap year Exception: if divisible by 400 → leap year 🔹 Inputs I used: Year 🔹 Code: year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap Year") else: print("Not a Leap Year") 🔹 Example: Year = 2024 → Leap Year Year = 1900 → Not a Leap Year Year = 2000 → Leap Year 🔹 Key Takeaway: Combining conditions correctly is important to avoid logical mistakes, even in simple problems #Day15 #Python #30DaysOfCode #LearningInPublic #DataAnalytics #ProblemSolving

To view or add a comment, sign in

Explore content categories