CBSE Class 11 Computer Science Question 29 of 39

Conditional and Looping Constructs — Question 29

Back to all questions
29
Question

Question 13

Write a program to check if the number is positive or negative and display an appropriate message.

Solution
number = int(input("Enter a number: "))
if number > 0:
    print("The number is positive.")
else:
    print("The number is negative.")
Output
Enter a number: 4
The number is positive.

Enter a number: -6
The number is negative.
Answer

number
=
int
(
input
(
"Enter a number: "
))
if
number
>
0
:
print
(
"The number is positive."
)
else
:
print
(
"The number is negative."
)
Output
Enter a number: 4
The number is positive.

Enter a number: -6
The number is negative.