Questions
































Q: Write a python program to check if a given number is positive negative or zero.

Last Updated : 17 Sep 2024 Jul 22, Jan 23, Jul 24

Solution:

# Get input from the user
num = int(input("Enter any number: "))

# Check if the number is zero, positive, or negative
if num == 0:
    print("Given number is zero")
elif num > 0:
    print("Given number is positive")
else:
    print("Given number is negative")

 

OUTPUT:

First Time Driven:
Enter any number: 25
Given number is positive

Second Time Driven:
Enter any number: 0
Given number is zero

 

Explanation:

  1. num = int(input("Enter any number: ")):

    • This line reads input from the user, converts it to an integer, and stores it in the variable num.
  2. Conditional Statements:

    • if num == 0:: Checks if the number is zero and prints the corresponding message.
    • elif num > 0:: Checks if the number is positive and prints the corresponding message.
    • else:: Covers the case where the number is negative and prints the corresponding message.

Meanwhile you can watch this video

Watch Video