Check if Number is Positive, Negative, or Zero
Take a number and print whether it's positive, negative, or zero.
BeginnerPhase 1 - Level 1: Simple ConditionsExample 1 of 10
check-if-number-is-positive-negative-or-zero.py
1# Take a number as input2num = float(input("Enter a number: "))34# Check if positive, negative, or zero5if num > 0:6 print("Positive")7elif num < 0:8 print("Negative")9else:10 print("Zero")
Output
Enter a number: 5 Positive Enter a number: -3 Negative Enter a number: 0 Zero
What's going on
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
else for the case when number equals 0Logic Flow:
1.Check if num > 0 → Print "Positive"
2.Else if num < 0 → Print "Negative"
3.Else (num == 0) → Print "Zero"
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum