Start building now

Choose how you want to begin this project.

Open it privately for practice or create a shared workspace to build it together.

No setup required • Guided steps inside the editor

Private practice

Open a private editor and work through the steps at your own pace.

Start project alone

Shared workspace

Create a live session so you can teach, pair, or build the project together.

What you'll build

A program that calculates parking costs and repeats until the user enters 0 hours.

What you'll learn

  • How to repeat a program using a loop
  • How to use if statements in a calculation
  • How to work with numeric input
  • How to stop a loop with a sentinel value

How it works

1

The user enters the number of hours parked.

2

If the user enters 0, the program stops.

3

Otherwise, the program asks whether the car is electric.

4

It works out the parking cost and prints the result.

Build path

These steps appear inside the editor so you can build one part at a time.

  1. 1

    Step 1

    Repeat until 0 is entered

    Use a loop so the program keeps running while hours_parked is not 0.

    Complete in the editorHint available
  2. 2

    Step 2

    Ask whether the car is electric

    Inside the loop, ask the user whether their car is electric or not.

    Complete in the editorHint available
  3. 3

    Step 3

    Work out the hourly rate

    If the car is electric, use £2 per hour. Otherwise, use £4 per hour.

    Complete in the editorHint available
  4. 4

    Step 4

    Calculate and print the total price

    Multiply the hourly rate by hours_parked and print the result.

    Complete in the editorHint available
  5. 5

    Step 5

    Ask for the next number of hours

    At the end of the loop, ask for hours_parked again so the program can continue or stop.

    Complete in the editorHint available

More to explore

Browse more guided projects, or come back and start this one whenever you are ready.