Skip to content
ExamSpine

Lesson 1.8 · Write it

Add ages

A whole programPython or Java5 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads two ages, each a whole number on its own line, and prints their total on one line.

  1. The total is the two ages added together.
  2. Print only the total, as a number, with nothing else on the line. Spaces at the end are ignored.

Your program is run several times. Only what it prints is checked.

In Python, use int to turn each typed line into a whole number before adding. In Java, use Integer.parseInt on each line.

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

  • two ages added (rule 1)

    You type

    1. typed: 10
    2. typed: 7

    It prints

    17
  • one age is 0 (rule 1)

    You type

    1. typed: 0
    2. typed: 5

    It prints

    5
solution.pySolution.java