Skip to content
ExamSpine

Lesson 1.9 · Write it

Ticket cost

A whole programPython or Java5 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads the price of one ticket (a whole number) on the first line and the number of tickets (a whole number) on the second line, and prints the total cost on one line.

  1. The total is the price times the number of tickets, plus a fixed booking fee of 5.
  2. The fee is added once, not once per ticket: total = price times count, plus 5.
  3. Print only the total, as a number. Spaces at the end are ignored.

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

In Python, use int to convert each line. 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 5 times: the 2 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.

  • price times count plus the fee (rules 1 and 2)

    You type

    1. typed: 10
    2. typed: 3

    It prints

    35
  • one ticket (rules 1 and 2)

    You type

    1. typed: 10
    2. typed: 1

    It prints

    15
solution.pySolution.java