← Back to Unit 1

Week 9 Lesson 2 Challenge

YEAR 9 DIGITAL TECHNOLOGIES • FILES CHALLENGE

Save the Booking Challenge

In this challenge, you will use files to save booking data into a CSV file.

🐾 SCENARIO

Imagine you are writing a Python program for the Pet Services business.

The business needs a simple booking system.

Right now, if the program closes, the booking disappears.

Your job is to make the booking stay saved by writing it into a file called bookings.csv.

🎯 YOUR GOAL

Build a program that follows these rules:

  1. Ask for the customer name.
  2. Ask for the service booked.
  3. Check whether bookings.csv already exists.
  4. If it exists, add the new booking to it.
  5. If it does not exist, create bookings.csv and start saving bookings in it.
Challenge Brief

Your booking system should work like this:

Step 1: Ask for booking details
Get the customer name and the service from the user.
Step 2: Check for the file
Work out whether bookings.csv already exists.
Step 3: If the file is missing
Create bookings.csv and begin storing bookings in it.
Step 4: If the file already exists
Add the new booking to the next line of the CSV file.

Important: Focus only on saving the booking to a CSV file. Do not add extra features.

💭 WHAT YOU SHOULD THINK ABOUT
  • What happens to normal variables when the program ends?
  • How can a program tell whether a file already exists?
  • When should the program create a new file?
  • When should it add to an existing file instead?
  • What should each line in a CSV file look like?
  • What message should the program print so the user knows the booking was saved?
📌 SUCCESS CRITERIA
  • Your program asks for a customer name and service.
  • Your program checks whether bookings.csv exists.
  • If the file exists, your program appends the booking.
  • If the file does not exist, your program creates it.
  • The file saved is a .csv file.
  • Your output is clear and readable.
📚 Where to look up file tools in Python

This challenge uses file handling. That means your program must work with a file on the computer instead of only using variables in memory.

Useful places to look
  • Python file handling in your reference wiki
  • Python Standard Library: https://docs.python.org/3/library/
  • Search terms like Python file exists or Python append to csv file

Key idea: A variable disappears when the program ends. A file does not.

Stage 1 Hint: Get the booking details first

Before saving anything, your program needs data to save.

Ask the user for the customer name and the service booked.

Stage 2 Hint: Check whether the file exists

Your program needs to make a decision before it writes anything.

Use Python to check whether bookings.csv already exists.

Stage 3 Hint: Write the booking into the CSV file

Now combine the file check and the file writing into one complete system.

First
Get the booking details from the user.
Second
Check whether bookings.csv exists.
Third
If needed, create the file. Otherwise, add the booking to it.
Finally
Print a message to confirm the booking was saved.
Programming tips
Hint 1: Keep the file name consistent

Use the same exact file name every time: bookings.csv.

Hint 2: A CSV line is just values separated by commas

A booking line might look like this: Praj,bath

Hint 3: Think about whether you are overwriting or adding

Opening a file in the wrong mode can wipe old bookings.

Make sure your choice matches the job you are trying to do.

Hint 4: Test it more than once

Run your program twice or more so you can check that new bookings are being added to the CSV file instead of replacing old ones.

💬 WHAT TO POST IN REPLY BELOW
  • Your code attached as a .py file
  • A screenshot or a copy of your bookings.csv file after at least 2 bookings
✅ REMEMBER

This challenge is about making the booking survive after the program closes.

Keep the system simple. Save the booking correctly first.