Skip to content
ExamSpine

Lesson 1.6 · Write it

ID card

A whole programPython or Java4 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads a name and a number, each on its own line, and prints an ID card on two lines:

Name: Ada
ID: 4821
  1. The first line printed starts with Name: and one space, then the name exactly as typed.
  2. The second line printed starts with ID: and one space, then the number exactly as typed.
  3. The name is typed first, then the number.
  4. Print nothing else. Spaces at the end of a line are ignored.

Your program is run several times, with different names and numbers typed each time. Only what it prints is checked.

In Python, read each line with input() and save it in a variable. In Java, the page starts you with a class, its main method and a Scanner called scanner: read each line with scanner.nextLine() and save it in a String variable.

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

  • a name and a number, labelled on two lines (rules 1 to 4)

    You type

    1. typed: Ada
    2. typed: 4821

    It prints

    Name: Ada
    ID: 4821
solution.pySolution.java