Skip to content
ExamSpine

Lesson 1.8 · Write it

Type line

A whole programPython or Java5 tests, 4 of them hidden

On a phone? Put the lines in order instead

Write a program that reads a name (text) on the first line and a floor number (a whole number) on the second line, and prints one line:

Ada is on floor 3.
  1. The line starts with the name exactly as typed.
  2. Then is on floor , with one space before is and one after floor.
  3. Then the floor number, followed by a full stop with no space before it.
  4. Print nothing else. Spaces at the end of the line are ignored.

The floor number is always a whole number. In Python, input() gives you text, so you need int() to turn it into a number, and str() to turn a number back into text for joining with +. In Java, read the line as text and use Integer.parseInt to get an int; Java's + turns a number into text automatically when the other side is a String.

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 5 times: the example below, and 4 hidden ones that check the rules above. Only what it prints is checked.

  • a name and a floor number (rules 1 to 4)

    You type

    1. typed: Ada
    2. typed: 3

    It prints

    Ada is on floor 3.
solution.pySolution.java