Sunday, 5 April 2026
Python Coding Challenge - Question with Answer (ID -050426)
Code Explanation:
Book: 100 Python Automation Projects for Smart Developers
Saturday, 4 April 2026
๐ Day 12/150 – Check Leap Year in Python
Samaksh Dubey April 04, 2026 Python Tips No comments
Welcome back to the 150 Days of Python series! ๐ฏ
Today, we’re solving a real-world logic problem — checking whether a year is a leap year.
This is a great exercise to understand:
- Conditional statements
- Logical operators (and, or)
- Writing clean, readable code
Problem Statement
Write a Python program to check whether a given year is a Leap Year or Not.
Understanding Leap Year Logic
Before coding, let’s understand the rules:
A year is a leap year if:
✔ Divisible by 4
❌ But NOT divisible by 100
✔ EXCEPTION: If divisible by 400, then it is a leap year
Year Result
2024 ✅ Leap Year
1900 ❌ Not Leap Year
2000 ✅ Leap Year
Method 1 – Using if-elif-else
year = 2024 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap Year") else: print("Not a Leap Year")
Code Explanation:
- year % 4 == 0
๐ Checks if year is divisible by 4 - year % 100 != 0
๐ Ensures it is NOT divisible by 100 - year % 400 == 0
๐ Special case: makes century years valid - and → both conditions must be true
- or → at least one condition must be true
๐ This full condition ensures accurate leap year calculation
Method 2 – Taking User Input
๐ What’s new here?
- input() → takes user input
- int() → converts string input into integer
๐ Always convert input when dealing with numbers!
Method 3 – Using a Function
๐ Why use a function?
- Code becomes reusable
- Cleaner structure
- Easy to test
๐ You can call this function anytime with different values
Method 4 – Using Python calendar Module
๐ Explanation:
- calendar.isleap(year)
๐ Built-in Python function
๐ Returns True or False
๐ This is the simplest and most reliable method
Important Things to Remember
✔ Always use correct logical condition
✔ Don’t forget parentheses ( ) in conditions
✔ Convert input using int()
✔ Built-in functions save time and reduce errors
Summary
| Method | Concept |
|---|---|
| if-else | Basic logic |
| User Input | Real-world usage |
| Function | Reusability |
| calendar module | Pythonic approach |
Python Coding Challenge - Question with Answer (ID -040426)
Code Explanation:
Book: BIOMEDICAL DATA ANALYSIS WITH PYTHON
Friday, 3 April 2026
๐ Day 9/150 – Check Positive or Negative Number in Python
Samaksh Dubey April 03, 2026 Python Tips No comments
1️⃣ Method 1 – Using If-Else Conditions
The simplest and most common approach.
Output
Positive number
✔ Easy to understand
✔ Best for beginners
2️⃣ Method 2 – Taking User Input
Make the program interactive.
num = float(input("Enter a number: ")) if num > 0: print("Positive number") elif num < 0: print("Negative number") else: print("Zero")
✔ Works with decimal numbers
✔ Useful in real-world applications
3️⃣ Method 3 – Using a Function
Reusable and clean approach.
def check_number(n): if n > 0: return "Positive" elif n < 0: return "Negative" else: return "Zero" print(check_number(-5))
✔ Reusable logic
✔ Cleaner code
4️⃣ Method 4 – Using Lambda Function
One-line solution using lambda.
✔ Compact code
✔ Useful for quick operations
๐ฏ Key Takeaways
Today you learned:
- Conditional statements (if, elif, else)
- Handling user input
- Writing reusable functions
- Using lambda expressions
๐ Day 2/150 – Add Two Numbers in Python
Samaksh Dubey April 03, 2026 Python Tips No comments
๐ Day 2/150 – Add Two Numbers in Python
๐ฏ What Should You Actually Use?
| Situation | Best Method | ||
|---|---|---|---|
| Normal programs |
| ||
| Reusable logic | Function | ||
| Many numbers | sum() | ||
| Interview discussion | Recursion / Bitwise | ||
| Functional programming | Lambda |
๐ญ Why Learn Multiple Ways?
Because programming isn’t about memorizing syntax.
It’s about:
-
Understanding concepts
-
Improving problem-solving
-
Writing clean code
-
Thinking differently
The more ways you know, the sharper your logic becomes.
Popular Posts
-
Deep learning is often presented as a combination of Python programming, neural networks, datasets, and powerful computing systems. Howeve...
-
Machine learning is often learned through Python, notebooks, datasets, and ready-made libraries. While practical implementation is extreme...
-
Machine learning is often described through algorithms, datasets, and programming frameworks. However, behind many of the most important t...
-
97 Things Every Programmer Should Know: Collective Wisdom from the Experts Programming is often taught through syntax, algorithms, framework...
-
Statistics is one of the most powerful tools for understanding data, but it can also be misunderstood and misused. A statistical result may ...
-
If you're learning Python or looking to level up your skills, you’re in luck! Here are 6 amazing Python books available for FREE — c...
-
What you'll learn Develop data engineering solutions with a minimal and essential subset of the Python language and the Linux environm...
-
Deep Learning has revolutionized the field of Artificial Intelligence, enabling machines to recognize images, understand natural language,...
-
Data science is often presented as a combination of programming, statistics, and machine learning. However, beneath many of the algorithms...
-
Deep Learning on Graphs: A Complete Guide to Graph Neural Networks, Graph Representation Learning, and Real-World AI Applications Introduc...

.png)
.png)
