Write a program to print whether the number entered by user is positive,
negative or zero?
Answers
Answer:
def check(num):
if num == 0:
print("The number you've entered is zero!")
elif num > 0:
print("The number you've entered is positive!")
else:
print("The number you've entered is negative")
num1 = float( input("Enter the number you want to check: "))
check(num1)
Explanation:
You've to get the number value as float because in int you can only store the integer values (which doesn't consist negative and fractional). Tell me if you want the program in any other language. :)
//Java Programming
import java.util.Scanner;
public class CheckPositive
{
public static void main (String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter A Number");
int x = sc.nextInt();
if (x > 0)
{
System.out.println("You entered a positive number");
}
else
{
if (x < 0)
{
System.out.println("You entered a negative number");
}
else
{
System.out.println("You entered a zero");
}
}
sc.close();
}
}