# Exercise: Water Park Tickets

Finish a water park's ticket script that checks the group's size with a while loop, prices each person's ticket by age and day with if, elif, else and and, and totals the group with a for loop over range, while pytest types the answers in and checks every line.

Apprentice · Python · Updated November 19, 2026

By Gregor Dzierzon

The ticket booth at Splash Valley Water Park prices a whole group at once, and its program stops after the first two questions. You'll finish it: make sure the group is a size the park allows, ask each person's age, print each ticket's price, and print the group's total. It uses everything in this chapter: comparisons, `if`, `elif` and `else`, `and` and `or`, a `while` loop and a `for` loop over `range()`. The tests run your script the way the booth's cashier would, typing the answers in for you, and check each line it prints.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-python-water-park-tickets](https://github.com/ask-codey/exercise-python-water-park-tickets), also linked from the **Exercise** box beside the lesson. Clone it into your `python-course` folder. In VS Code's terminal:

```bash
cd ~/python-course
git clone https://github.com/ask-codey/exercise-python-water-park-tickets.git
```

Git makes a folder, `exercise-python-water-park-tickets`, with the exercise code inside. *Get the Exercise Code with Git* walks through cloning step by step, if you'd like a reminder. Open that folder in VS Code (**File > Open Folder**), open its terminal with **Terminal > New Terminal**, and make the exercise's virtual environment, the same three steps as in the exercises before. On Windows (PowerShell):

```powershell
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
```

On a Mac (zsh):

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

The prompt starts with `(.venv)` once the virtual environment is on. The exercise's README says what each command does, and what to do if PowerShell won't run the second one.

The folder holds:

- `tickets.py`: the prices in a comment, the first two questions, and the four steps to write. For you to finish.
- `tests/test_tickets.py`: the tests, which run `tickets.py`, type the answers in, and check the lines it prints. You don't need to change it.
- `requirements.txt` and `pytest.ini`: the package the tests need, and where pytest finds the tests.

## What to do

The park's prices: under 3 is free, 3 to 12 is $18, 13 to 64 is $30, and 65 and over is $20. On a Saturday or a Sunday, every ticket that isn't free costs $6 more. A group is 1 to 8 people.

`tickets.py` asks two questions with `input()`: the day of the visit, which it turns into lowercase, and how many people are in the group, which it turns into a whole number. The rest is yours, in four steps:

1. **Check the group's size.** While it's less than 1 or more than 8, print `Groups are 1 to 8 people.` and ask the same question again.
2. **Work out whether it's the weekend:** the day is `saturday` or `sunday`.
3. **Price each ticket.** For each person, numbered from 1, ask their age with `age = int(input(f"How old is person {person}? "))`. Work out their price from their age, add $6 at the weekend unless the ticket is free, print the ticket's line, and add the price to the group's total.
4. **Print the total** on one more numbered line.

Typing `Saturday`, `3`, then the ages `35`, `8` and `2`, the lines are:

```text
1) Ticket for age 35: $36
2) Ticket for age 8: $24
3) Ticket for age 2: $0
4) Group total: $60
```

The README's *The rules* gives the exact wording of every line, and lists every group the tests type and every line they check.

## Check your work

Run the tests from the exercise folder, with the virtual environment on:

```bash
pytest
```

At first all 14 tests fail. That's expected: the script doesn't print any tickets yet, and each line you get right turns its tests green. A failing test's message says what it typed, the line it expected and what came back, for example *Typing 'Saturday', '3', '35', '8', '2', tickets.py should print the line: 3) Ticket for age 2: $0, but it printed: 3) Ticket for age 2: $6.* A test that says *tickets.py was still running after 10 seconds* has found a `while` loop that never ends.

To try it the way the cashier would, run `python tickets.py` and type the answers yourself.

## Hints

- **Work one group through by hand first.** On a Saturday, the 35-year-old's $30 ticket becomes $36 and the 8-year-old's $18 becomes $24, while the 2-year-old's stays free: $60 in all.
- **Check the ages from the youngest up.** The narrowest condition goes first, and each `elif` picks up what's left. *Making Decisions with if, elif and else* shows the same four prices.
- **A free ticket stays free.** Add the $6 only when it's the weekend `and` the price is more than 0. *Combining Conditions with and, or and not* shows how the two join.
- **The asking loop needs its own `input()`.** Inside the `while`, ask again, or `group_size` never changes and the loop never ends. *Repeating with while* shows the same shape for a height.
- **Count the people from 1.** `range(1, group_size + 1)` gives 1 up to the group's size, because `range` leaves its stop out. Start the total at 0 before the loop and add to it with `+=`.

## When you're done

Every test is green: pytest's last line says `14 passed`. And running `python tickets.py`, typing `Friday`, then `0`, `9` and `2` for the group's size, then the ages `10` and `30`, shows:

```text
What day is your visit? Friday
How many people are in your group? 0
Groups are 1 to 8 people.
How many people are in your group? 9
Groups are 1 to 8 people.
How many people are in your group? 2
How old is person 1? 10
1) Ticket for age 10: $18
How old is person 2? 30
2) Ticket for age 30: $30
3) Group total: $48
```

Now look at your price rules. If the park added a $25 price for teenagers, 13 to 17, where would that one new `elif` go, so that a 15-year-old reaches it and a 40-year-old doesn't?

## Submit your exercise

The exercise is how you finish this lesson. When your work is done, put it on GitHub in a repo of your own, then submit that repo's address here. *Hand In Your Work with Git* walks through each step.

1. On GitHub, click **+**, then **New repository**. Name it (for example `exercise-python-water-park-tickets`), choose **Public**, and click **Create repository**. Leave out the README: your folder already has one.
2. In VS Code's terminal, in your exercise folder, send your work to your new repo. Point your copy at your own repo, then commit and push:

   ```bash
   git remote set-url origin https://github.com/your-name/exercise-python-water-park-tickets.git
   git add .
   git commit -m "My solution"
   git push -u origin main
   ```

3. Paste your repo's address, such as `https://github.com/your-name/exercise-python-water-park-tickets`, into **Submit your exercise** on this page. The site checks that the repo is public and holds your commits, and then the lesson is complete.

Changed something after you submitted? Push it, and submit again: your latest submission is the one that counts.

## So what

Ask, check, decide, repeat: a booth that prices any group on any day is the same shape as most programs that handle real people, and you built every piece of it.

## Key terms

- [if Statement](https://www.ask-codey.com/glossary/if-statement)
- [elif](https://www.ask-codey.com/glossary/elif)
- [while Loop](https://www.ask-codey.com/glossary/while-loop)
- [for Loop](https://www.ask-codey.com/glossary/for-loop)
- [range()](https://www.ask-codey.com/glossary/range)
- [pytest](https://www.ask-codey.com/glossary/pytest)

## Related

- [True, False and Comparisons](https://www.ask-codey.com/lessons/python-booleans-and-comparisons)
- [Making Decisions with if, elif and else](https://www.ask-codey.com/lessons/python-if-elif-else)
- [Combining Conditions with and, or and not](https://www.ask-codey.com/lessons/python-and-or-not)
- [Repeating with while](https://www.ask-codey.com/lessons/python-while-loops)
- [Counting with for and range](https://www.ask-codey.com/lessons/python-for-loops-and-range)

Source: https://www.ask-codey.com/lessons/exercise-python-water-park-tickets
