CBSE Class 12 Computer Science Question 95 of 105

Python Revision Tour — Question 1

Back to all questions
1
Question

Question 1

Write a program to print one of the words negative, zero, or positive, according to whether variable x is less than zero, zero, or greater than zero, respectively.

Solution
x = int(input("Enter x: "))

if x < 0:
    print("negative")
elif x > 0:
    print("positive")
else:
    print("zero")
Output
Enter x: -5
negative

Enter x: 0
zero

Enter x: 5
positive
Answer