#09 - Corner Shop
Flowchart
Pseudocode
products =
"Twix": 4.00
"Mars": 5.00
"Skittles": 7.00
"Toblerone":10.00
"Nerds":3.00
list prodcut()
for x in products
output product name, product price
loop until not true:
choice 1 input = "would you want to add a new product"
if choice 1 is yes:
add_product()
break
elif choice 1 is no
remove_product()
break
else:
outpunt "incorrect value"
define add_prodct():
food = input "Input item you want to add: "
cost = input "Input item cost"
Code
products = {
"Twix":4.00,
"Mars":5.00,
"Skittles":7.00,
"Toblerone":10.00,
"Nerds":3.00,
}
def list_product():
for x in products:
print(x,'£'+str(products[x]))
while True:
choice_1=input('\nWould you want to add a new product? (Y/N) ').upper()
if choice_1 == 'Y':
add_product()
break
elif choice_1 == 'N':
remove_product()
break
else:
print('Incorrect value')
def add_product():
food=input('Input item you want to add: ')
cost=float(input('Input the cost for the item: (without £) '))
products[food]=cost
for x in products:
print(x,'£'+str(products[x]))
while True:
choice_2=input('Would you want to add another product? (Y/N) ').upper()
if choice_2 == 'Y':
add_product()
elif choice_2 == 'N':
remove_product()
else:
print('Incorrect value')
def remove_product():
while True:
removal_choice=input('Would you want to remove an item? (Y/N) ').upper()
if removal_choice=='Y':
for x in products:
print(x,'£'+str(products[x]))
removal=input('Input item you want to remove: ')
products.pop(removal)
for x in products:
print(x,'£'+str(products[x]))
bill()
break
elif removal_choice=='N':
bill()
break
else:
print('Incorrect value')
while True:
choice_3=input('Do you want to process a order? (Y/N) ').upper()
if choice_3=='Y':
bill()
break
elif choice_3=='N':
break
else:
print('Incorrect value')
def bill():
for x in products:
print(x,'£'+str(products[x]))
cost=0.0
while True:
item=input('Input the item you want to add to the bill: ')
if item in products:
cost=cost+products[item]
else:
print('Item is not in stock')
choice_4=input('Do you have another item to add? (Y/N) ').upper()
if choice_4=='Y':
pass
elif choice_4=='N':
break
else:
print('Incorrect value')
print('The bill total is £'+str(cost))
with open('bill.txt', 'w') as f:
f.write('The bill total is £'+str(cost))
list_product()