Link Search Menu Expand Document

02 Hot Beverage Vending Machine

How would you shape the behaviour of your favourite vending machine? In this second Python programming assignment, you will prototype some logic with branches and operators to drive through alternative paths in your program. It will shape the behaviour of a hot beverage vending machine depending on the user choices. You will also use files to store and retrieve available supplies, such as the number of remaining cups or the amount of sugar.


Through this assignment, we explore the following concepts:

Branching

Compound statement

Operator

Boolean

Object

File

Logging

Flow chart

đź’¨ Brief Refresher

Let’s start with a brief refresher of the topics we covered in previous assignments that might be useful to remember.

  • Algorithm – In this series of tutorials, we define an algorithm in a broad sense: a set of instructions that tells the computer what to do.

  • Variable – For the computer to learn, it must memorise information. It is the role of the variables: a storage location in the computer’s memory, paired with a name. The name enables us to retrieve the information in our programme. To create a new variable, we need three elements:

    • name what do we call this thing that we want the computer to remember?
    • type what type of data does it contain?
    • initial value What is its starting value?
  • Data Type – The computer classifies the data it handles by type. It enables it to know what is meaningful to do with this data. We saw four examples of data types so far:

    • int can keep integer numbers in memory, values such as 12 or -134
    • float can keep decimal numbers in memory, values such as 12.0 or -134.3
    • char can keep a single character in memory, values such as 'A', 'b', '1' or '!'
    • string can keep a sequence of characters in memory, values such as "python" or "My name is Bob."
  • Debugging – Sometimes, the code we write might lead to unexpected behaviour. Debugging is the iterative process of investigating and adjusting this behaviour to the one we want. It is critical to formulate our goal and the undesired behaviour in plain English to conduct this investigation effectively.

⏰ Time Management and Expectations

This assignment involves a range of new concepts which takes time to explore. Steps 2 and 5 are critical. Take your time to practice, to make it your code by developing beyond the examples.

Next: Step 1 - Review


Table of contents