1️⃣ Method 1 – Using If-Else Conditions
The simplest and most common approach.
num = 10
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
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.
check = lambda n:
"Positive"
if n > 0
else ("Negative" if n < 0 else "Zero")
print(check(0))
✔ 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
.png)

0 Comments:
Post a Comment