Lesson 2.3 · Write it
Sign check
A whole programPython or Java6 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a whole number and prints its sign.
- If the number is greater than 0, print the number followed by
is positive. - If the number is less than 0, print the number followed by
is negative. - If the number is exactly 0, print the number followed by
is zero. - Print exactly one of those three lines. Spaces at the end are ignored.
Your program is run several times. Only what it prints is checked.
In Python, use int to convert. In Java, use Integer.parseInt.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
a positive number (rule 1)
You type
- typed: 5
It prints
5 is positive
a negative number (rule 2)
You type
- typed: -3
It prints
-3 is negative
zero (rule 3)
You type
- typed: 0
It prints
0 is zero