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 aloneShared 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
The user enters the number of hours parked.
If the user enters 0, the program stops.
Otherwise, the program asks whether the car is electric.
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
Step 1
Repeat until 0 is entered
Use a loop so the program keeps running while hours_parked is not 0.
- 2
Step 2
Ask whether the car is electric
Inside the loop, ask the user whether their car is electric or not.
- 3
Step 3
Work out the hourly rate
If the car is electric, use £2 per hour. Otherwise, use £4 per hour.
- 4
Step 4
Calculate and print the total price
Multiply the hourly rate by hours_parked and print the result.
- 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.
More to explore
Want a different challenge?
Browse more guided projects, or come back and start this one whenever you are ready.