Write a program to check whether a number is positive or negative. Take an integer, num, as an input from the console using input() function and print the result to the console as shown in the sample test case. Sample Input and Output 1: num: 02 positive Sample Input and Output 2: num: -52142 negative Sample Input and Output 3: num: 0 zero
Question
Write a program to check whether a number is positive or negative. Take an integer, num, as an input from the console using input() function and print the result to the console as shown in the sample test case.
Sample Input and Output 1: num: 02 positive
Sample Input and Output 2: num: -52142 negative
Sample Input and Output 3: num: 0 zero
Solution
Sure, here is a simple Python program that checks whether a number is positive, negative or zero:
# Take an integer as an input from the user
num = int(input("Enter a number: "))
# Check whether the number is positive, negative or zero
if num > 0:
print("positive")
elif num < 0:
print("negative")
else:
print("zero")
This program works by first taking an integer input from the user. It then checks if the number is greater than 0, in which case it prints "positive". If the number is not greater than 0, it checks if it's less than 0, in which case it prints "negative". If the number is neither greater than nor less than 0, it must be 0, so it prints "zero".
Similar Questions
Write a program to find whether a given integer is positive or negative.Sample Input 1:Enter the number:45Sample Output 1:45 is a positive numberSample Input 2: Enter the number:-364Sample Output 2:-364 is a negative numberScanner sc = new Scanner(System.in);public static void main(String[] args) {import java.util.*;public class Main {if(num>=0)System.out.println(num+" is a negative number");elseSystem.out.println("Enter the number:");int num=sc.nextInt(); }}System.out.println(num+" is a positive number");
Embark on a numerical adventure with David. Design a program to classify an input integer as positive, negative, or zero. Your goal is to determine the sign of the given number using relational and ternary operators and display the output.Input format :The input consists of an integer n, representing the number to be analyzed.Output format :The output displays the message "The number is [positive/negative/zero]" based on the analysis of the given number.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the given test cases fall under the following constraints:−106 ≤ n ≤ 106Sample test cases :Input 1 :-9874Output 1 :The number is negativeInput 2 :7456Output 2 :The number is positiveInput 3 :0Output 3 :The number is zeroNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0
Check if a Number is Positive and Negative in Python
Single File Programming QuestionProblem Statement Embark on a numerical adventure with David. Design a program to classify an input integer as positive, negative, or zero. Your goal is to determine the sign of the given number using relational and ternary operators and display the output.Input format :The input consists of an integer n, representing the number to be analyzed.Output format :The output displays the message "The number is [positive/negative/zero]" based on the analysis of the given number.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the given test cases fall under the following constraints:−106 ≤ n ≤ 106Sample test cases :Input 1 :-9874Output 1 :The number is negativeInput 2 :7456Output 2 :The number is positiveInput 3 :0Output 3 :The number is zero
Given an integer input , whether the given input is "Positive" or "Negative" or "Zero" and print the corresponding messageInput Format:Enter an integer as a input Output Format: Print the output as "Negative" or "Positive" or "Zero"Constraints:1 <= INPUT <= 10^15Sample Input 1:-98Sample Output 1:NEGATIVESample Input 2:0Sample Output 2:ZERO
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.