Coding Task: 02.04 Cafe Simulator

In this exercise, you will write a program that lets a user spend money on cafe food and drinks using a simple looping menu. Some of the code has been written for you!

Your Task

In the editor below, fill in the blanks (________) so that the program behaves like the example screenshot below.

Python Reference Sheet

Remember to use the Python reference sheet to help you with your code! Click on one of the buttons below:

Requirements

  • The program should run without any errors.
  • The program should ask for a starting number of dollars. It should then present a simple menu where the user can type a to buy a muffin for 10 dollars or b to buy a coffee for 5 dollars. The program should end when the user runs out of money.
  • It’s possible that the user might spend more money than they actually have. That’s okay, As long as the program stops when they have 0 dollars or less!
  • Hint: Don’t forget to convert the starting_dollars variable to an integer using the int() command, or you might get an error! What happens when you don’t convert the variable to an integer? Why do you think this happens?

Example

Below is an example of how the program should run:

Enter starting $: 20
Current money:
20
Enter [a] to buy a muffin for $10
Enter [b] to buy a coffee for $5
Enter your choice: a
Gobble gobble gobble!

Current money:
10
Enter [a] to buy a muffin for $10
Enter [b] to buy a coffee for $5
Enter your choice: b
Gulp gulp gulp!

Current money:
5
Enter [a] to buy a muffin for $10
Enter [b] to buy a coffee for $5
Enter your choice: b
Gulp gulp gulp!

You've run out of money, sorry!
Game over.
Scroll to Top