Answer To: You are tasked with creating a text-based program for simulating a supermarket self-service checkout...
Abr Writing answered on May 09 2020
Supermarket Self-Service Checkout.html
In [1]:
%run main.py
----- Welcome to FedUni checkout! -----
Please enter the barcode of the product: 123
Milk 2.0
Would you like to scan another product? (Y/N)y
Please enter the barcode of the product: 456
Coffee 3.0
Would you like to scan another product? (Y/N)y
Please enter the barcode of the product: 999
This product does not exist in our inventory.
Would you like to scan another product? (Y/N)n
Payment due: 5.0
Please enter an amount to pay: 1
5.0
1.0
Payment due: 4.0
Please enter an amount to pay: -3
We don't accept negative money!
Please enter an amount to pay: 5
4.0
5.0
----- Final Receipt -----
Milk 2.0
Coffee 3.0
Total amount due: 5.0
Amount received: 6.0
Change given: 1.0
Thank you for shopping at FedUni!
(N)ext customer, or (Q)uit?q
main.py
from CheckoutRegister import CheckoutRegister
# If the final option of (N)ext customer is chosen, the program runs again
moreCustomer = True
while moreCustomer:
print('----- Welcome to FedUni checkout! -----')
register = CheckoutRegister()
#
while True:
# Taking user input: barcode of the product
barcode = float(input('Please enter the barcode of the product: '))
# Scanning the product using the function scan_item
register.scan_item(barcode)
# Taking user input: More products or not?
prod = input('Would you like to scan another product? (Y/N)')
# Taking decision based on customer's input
if prod.lower() == "n":
# Calculating the amount due by the customer
register.due()
due = 0
for idx in register.itemList:
due += register.product.price[idx]
print('Payment due: ', register.total)
total = register.total
#
while True:
tmp = register.accept_payment(float(input('Please enter an amount to pay: ')))
if tmp == "negative" :
continue
print(total)
print(register.pay[-1])
if total > register.pay[-1]:
print('Payment due: ', total - register.pay[-1])
total = total - register.pay[-1]
else:
break
# Printing the receipt
register.print_receipt()
break
else:
continue
# Taking user input: More customers?
next = input('(N)ext customer, or (Q)uit?')
if next.lower == 'n':
continue
else:
moreCustomer = False
Product.py
import pandas as pd
class Product:
def __init__(self):
fileName = 'products.csv'
# reading product data from fileName (.CSV file)
df = pd.read_csv(fileName)
self.barcode = list(df.barcode)
self.name = list(df.name)
self.price = list(df.price)
products.csv
barcode,name,price
123,Milk,2
212,Bread,3
456,Coffee,3
923,Sugar,5.5
Supermarket Self-Service Checkout.ipynb
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"----- Welcome to FedUni checkout! -----\n",
"Please enter the barcode of the product: 123\n",
"Milk 2.0\n",
"Would you like to scan another product? (Y/N)y\n",
"Please enter the barcode of the product: 456\n",
"Coffee 3.0\n",
"Would you like to scan another product? (Y/N)y\n",
"Please enter the barcode of the product: 999\n",
"This product does not exist in our inventory.\n",
"Would you like to scan another product? (Y/N)n\n",
"Payment due: 5.0\n",
"Please enter an amount to pay: 1\n",
"5.0\n",
"1.0\n",
"Payment due: 4.0\n",
"Please enter an amount to pay: -3\n",
"We don't accept negative money!\n",
"Please enter an amount to pay: 5\n",
"4.0\n",
"5.0\n",
"----- Final Receipt ----- \n",
"Milk 2.0\n",
"Coffee...