Performance Task
Performance Task
@author: 1599404
'''
#imports
import random
#functions
def receipt(stotal, cart):
#this function prints the receipt of the user
print(f'|{"Product":^60}|')
#iteration
for i in range(len(cart)):
print(f'|{cart[i]:^60}|')
print(
f'|{"Subtotal: " + str(stotal):^30}|{"Total with tax: $" + str(stotal * 0.08 + stotal):^30}|'
)
#MAIN
#dictionary. This dictionary has the specification of each item in the store.
specifications = {
'MACBOOK AIR': {
'Year': '2022',
'CPU': 'Apple M2',
'RAM': '32 GB',
'Storage': '512 GB/1 TB',
'Price': 1699
},
'DELL XPS 13 OLED': {
'Year': '2012',
'CPU': 'Intel Core i7',
'RAM': '16 GB',
'Storage': '512 GB',
'Price': 1299
},
'HP VICTUS': {
'Year': '2022',
'CPU': 'Intel Core i7-12800',
'GPU': 'NVIDIA GeForce RTX 3090 8GB',
'RAM': '64 GB',
'Storage': '1TB',
'Price': 1999
},
'IPHONE 14': {
'Year': '2022',
'Storage': '256 GB',
'Price': 899
},
'SAMSUNG GALAXY S23': {
'Year': '2023',
'Storage': '256 GB',
'Price': 799
},
'IPHONE X': {
'Year': '2017',
'Storage': '64 GB',
'Price': 100
}
}
#This dictionary has the number of items available in the store. The amount is random each
time the program is started.
inventory = {
'MACBOOK AIR': random.randint(0, 11),
'DELL XPS 13 OLED': random.randint(0, 11),
'HP VICTUS': random.randint(0, 11),
'IPHONE 14': random.randint(0, 11),
'SAMSUNG GALAXY S23': random.randint(0, 11),
'IPHONE X': random.randint(0, 11),
}
#I create empty variables to use later in a loop
product = ''
shopping_cart = []
user_action = ''
subTotal = 0
paid = 0
change = 0
#Welcoming the user
print(f'|{" WELCOME TO ORANGE ELECTRONICS STORE! ":^61}|')
print('-' * 63)
print(f'|{"Item":^30}|{"Price":^30}|')
print('-' * 63)
#iteration to print the inventory of the store with the respective price of the item
for i, b in specifications.items():
print(f'|{i:^30}|{"$" + str(specifications[i]["Price"]):^30}|')
#I print the items and the number of items available
print('\n\n')
print(
f'{"---------------------------Inventory---------------------------":^60}')
print(f'|{"Item":^30}|{"Available":^30}|')
print('-' * 63)
for i, b in inventory.items():
print(f'|{i:^30}|{inventory[i]:^30}|')
#iteration
while (user_action != '-1' or user_action != 'see' or user_action != 'SEE'
or user_action != 'buy' or user_action != 'BUY'):
user_action = input('\nDo you want to see or buy a product? (-1 to cancel) ')
#selection
if user_action == '-1':
print('Thanks for visitng us! :D')
break
else:
#selection
if (user_action == 'see' or user_action == 'SEE' or user_action == 'See'):
#iteration
while user_action != 'no':
#SELECTION
if user_action != 'no' or user_action != 'NO':
#user input
product = input('What product do you want to see?')
product = product.upper()
#selection
if product not in specifications:
print('Item not found in inventory')
else:
#iteration
for i in specifications[product]:
print(i + ':', specifications[product][i])
else:
break
#user input
user_action = input('Do you want to see another product? ')
#selection
elif user_action == 'buy' or user_action == 'BUY' or user_action == 'Buy':
#iteration
while user_action != 'no':
#selection
if user_action != 'no':
#user input
product = input('What product do you want to buy? (-1 to cancel) ')
product = product.upper()
#Selection
if product != '-1':
#selection
if product in inventory:
#selection
if inventory[product] != 0:
shopping_cart.append(product)
subTotal += specifications[product]['Price']
inventory[product] -= 1
print('\nItem added to your Shopping cart!')
receipt(subTotal, shopping_cart)
user_action = input(
'Do you want to add something else to your cart? ')
else:
print(
'Sorry :( \nThis item is unavailable because we don\'t have enough in stock. \nTry
again later or select another item'
)
user_action = input(
'Do you want to add something else to your cart? ')
else:
print('Item not found')
else:
receipt(subTotal, shopping_cart)
print()
total = subTotal * 0.08 + subTotal
paid = int(input('With how much will you pay? '))
if paid > total:
change = round(paid - total, 2)
print('Here is your change: $' + str(change))
elif paid == total:
print('Thank you for your buy!')
exit()
else:
if paid < total:
while paid < total:
if paid < total:
print('Insufficient money.')
paid = int(input('With how much will you pay? '))
if paid > total:
change = round(paid - total, 2)
print('Here is your change: $' + str(change))
print('Thanks for your buy! ')
exit()
elif paid == total:
print('Thank you for your buy!')
exit()
receipt(subTotal, shopping_cart)
print()
total = subTotal * 0.08 + subTotal
paid = int(input('With how much will you pay? '))
if paid > total:
change = round(paid - total, 2)
print('Here is your change: ' + str(change))
print('Thanks for your buy! ')
elif paid == total:
print('Thank you for your buy!')
exit()
else:
if paid < total:
while paid < total:
if paid < total:
print('Insufficient money.')
paid = int(input('With how much will you pay? '))
if paid > total:
change = round(paid - total, 2)
print('Here is your change: $' + str(change))
print('Thanks for your buy! ')
exit()
elif paid == total:
print('Thank you for your buy!')
exit()
else:
print('Please say if you want to SEE or BUY an object')