Welcome to the Snack Machine Demo project! This is a Python programming exercise designed to help you learn the basics of Python programming by building a virtual snack machine.
- This project is designed to run in GitHub Codespaces
- No local installation required!
- Click the green "Code" button on GitHub
- Select "Codespaces" tab
- Click "Create codespace on main" (or your current branch)
- Wait for the codespace to load (this may take a few minutes the first time)
Once your codespace is ready, you can run the app in two ways:
Option A: Using the Terminal
- Open the terminal (Terminal → New Terminal from the menu)
- Type the following command and press Enter:
python main.py
Option B: Using VS Code's Run Button
- Open the
main.pyfile - Click the "Run Python File" button (
▶️ ) in the top-right corner - Or press
Ctrl+F5(Windows/Linux) orCmd+F5(Mac)
To verify that your code is working correctly, you can run the automated tests:
- Open the terminal (Terminal → New Terminal from the menu)
- Type the following command and press Enter:
Or for more detailed output:
pytest
pytest -v
All tests should pass! If you make changes to the code, run the tests again to make sure everything still works.
When you run the app, you should see:
🎯 Welcome to the Python Snack Machine!
=============================================
📋 Available snacks:
1. 🍿 Chips - $1.50
2. 🍫 Chocolate Bar - $2.00
3. 🥜 Granola Bar - $1.25
4. 🥤 Soda - $1.75
------------------------------
Enter the number of your choice (1-4):
snack-machine/
├── main.py # Main application file (start here!)
├── test_main.py # Automated tests for the app
├── requirements.txt # Python dependencies
├── .devcontainer/ # Codespace configuration
└── README.md # This file
Now that you have the basic setup working, you can start building your snack machine! Here are some ideas:
- Add a menu of snacks with prices
- Create functions to handle money input
- Add inventory tracking
- Build a user interface
- Make sure you're in the correct directory (you should see
main.pyin the file explorer) - Try running
python3 main.pyinstead ofpython main.py - Check that your codespace has finished loading completely
- Ask your instructor
- Check the VS Code terminal for error messages
- Make sure all files are saved before running
Happy coding! 🐍🥤