Logic Building
# Take a number as input
num = float(input("Enter a number: "))
# Check if positive, negative, or zero
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")Output
Enter a number: 5 Positive Enter a number: -3 Negative Enter a number: 0 Zero
This program demonstrates basic conditional logic using if-elif-else.
Key Concepts:
- Use
>to check if number is greater than 0 (positive) - Use
<to check if number is less than 0 (negative) - Use
elsefor the case when number equals 0
Logic Flow:
- Check if num > 0 → Print "Positive"
- Else if num < 0 → Print "Negative"
- Else (num == 0) → Print "Zero"