Lesson 2.7 · Write it
Range with and
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 checks whether it is in the range 1 to 100 (inclusive), using one condition with and (Python) or && (Java).
- Always print
Number:followed by the number on the first line. - If the number is at least 1 and at most 100, print
In range. Otherwise, printOut of range. - Spaces at the end of a line are ignored.
Your program is run several times. Only what it prints is checked.
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.
in range (rule 2)
You type
- typed: 50
It prints
Number: 50 In range
below range (rule 2)
You type
- typed: 0
It prints
Number: 0 Out of range
lower boundary, included (rule 2)
You type
- typed: 1
It prints
Number: 1 In range