Professional Documents
Culture Documents
4. SOURCE CODE
5. INPUT/OUTPUT INTERFACE
6. CONCLUSION
1
INTRODUCTION
PYTHON DESCRIPTION:
structures, combined with dynamic typing and dynamic binding, make it very
to learn syntax emphasizes readability and therefore reduces the cost of program
program modularity and code reuse. The Python interpreter and the extensive
standard library are available in source or binary form without charge for all
cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input
will never cause a segmentation fault. Instead, when the interpreter discovers an
error, it raises an exception. When the program doesn't catch the exception, the
breakpoints, stepping through the code a line at a time, and so on. The debugger
2
is written in Python itself, testifying to Python's introspective power. On the
other hand, often the quickest way to debug a program is to add a few print
statements to the source: the fast edit-test-debug cycle makes this simple
ABOUT PROJECT
The logic of Vending Machine
vending machine. The three parameters this function will accept are the
items_data dictionary, the run variable with a boolean value, and the item
list, which includes all the items the user desires. A while loop is used,
The product id of the desired item must be entered here. If the product id is
less than the total length of items_data dictionary, the entire set of id
properties must be added to the list of the item; otherwise, the message
"Wrong Product ID" will be printed. If the user declines, the run variable
3
will change to False and they will be prompted to add more items. A prompt
will ask if you want to print the entire bill or just the total sum
4
WORKING DESCRIPTION
Setting Up Our Code | We'll start by setting up our code. This will involve
creating a list of items and their prices, and setting up variables to keep track
of the inserted money and selected item.
|Coding the Item Selection | The next step is to code the item selection. This
will involve creating a function that allows the user to select an item and
checks if the item is available.
| Coding the Money Insertion | After the item selection, we'll code the
money insertion. This will involve creating a function that allows the user to
insert money and keeps track of the total inserted money.
Coding the Item Dispensing | Once the item has been selected and the
money has been inserted, we'll code the item dispensing. This will involve
creating a function that checks if enough money has been inserted and, if so,
dispenses the item.
Coding the Change Return | The final step in coding our vending machine is
to code the change return. This will involve creating a function that
calculates the change to be returned and returns it to the user.
Testing Our Vending Machine Code | After we've coded our vending
machine, it's important to test it to make sure it works as expected. We'll go
5
through how to test each function and what to look for to ensure it's working
correctly.
Troubleshooting Common Issues | As with any coding project, you may run
into issues along the way. We'll go over some common issues you might
encounter when coding a vending machine and how to troubleshoot them.
Conclusion and Next Steps | In this lesson, we've learned how to code a
basic vending machine. But there's always more to learn! We'll discuss next
steps for expanding your knowledge and improving your vending machine
code.
6
SOURCE CODE
items_data = [
"itemId": 0,
'itemPrice': 120,
},{
"itemId": 1,
"itemName": "5Star",
'itemPrice': 30,
},{
"itemId": 2,
"itemName": "perk",
'itemPrice': 50,
},{
"itemId": 3,
"itemName": "Burger",
'itemPrice': 200,
},{
"itemId": 4,
"itemName": "Pizza",
'itemPrice': 300,
},]
7
item = []
reciept = """
"""
sum = 0
run = True
for i in items_data:
print(
while run:
buyItem = int(
input("\n\nEnter the item code for the item you want to buy: "))
item.append(items_data[buyItem])
else:
moreItems = str(
8
input("type any key to add more things, and type q to stop: "))
if moreItems == "q":
run = False
receiptValue = int(
input(("1. Print the bill? 2. Only print the total sum: ")))
if receiptValue == 1:
print(createReceipt(item, reciept))
elif receiptValue == 2:
print(sumItem(item))
else:
print("INVALID")
def sumItem(item):
sumItems = 0
for i in item:
sumItems += i["itemPrice"]
return sumItems
for i in item:
reciept += f"""
\t{i["itemName"]} -- {i['itemPrice']}
"""
reciept += f"""
9
\tTotal --- {sumItem(item)}
"""
return reciept
# Main Code
INPUT/OUTPUT CONSOLE
10
11
12