print("Hello there!")
cont = "yes"
while cont == "yes" or cont == "Yes" or cont == "YES":
print("Choose an option below:")
print("1) Calculate the value of different product sizes")
print("2) Calculate the sale price")
print("3) Calculate the discount")
print("4) Create a shopping list")
print("5) Exit")
option = float(input("Choose an option (1/2/3/4/5): "))
if option == 4:
import os,sys,time
sl = []
try:
f = open("Your_shopping_list.txt","r")
for line in f:
sl.append(line.strip())
f.close()
except:
pass
def mainScreen():
print("Your list contains",len(sl),"items.")
print("Please choose from the following options:")
print("1) Add to the list")
print("2) Delete from the list")
print("3) View the list")
print("4) Quit the program")
choice = input("Enter your choice here (1/2/3/4): ")
if len(choice) > 0:
if choice == "1":
addScreen()
elif choice == "2":
deleteScreen()
elif choice == "3":
viewScreen()
elif choice == "4":
sys.exit()
else:
mainScreen()
else:
mainScreen()
def addScreen():
print("Please enter the name of the item that you want to add.")
print("Press ENTER to return to the main menu.")
item = input("Item: ")
if len(item) > 0:
sl.append(item)
print("Item added.")
saveList()
time.sleep(1)
addScreen()
else:
mainScreen()
def viewScreen():
for item in sl:
print(item)
print("Press ENTER to return to the main menu")
input()
mainScreen()
def deleteScreen():
global sl
count = 0
for item in sl:
print(count, " - ", item)
count = count + 1
print("Press ENTER to return to the main menu.")
print("Which item do you want to remove?")
choice = input("Enter your choice here: ")
if len(choice) > 0:
try:
del sl[int(choice)]
print("Item deleted...")
saveList()
time.sleep(1)
except:
print("Invalid number")
time.sleep(1)
deleteScreen()
else:
mainScreen()
def saveList():
f = open("Your_shopping_list.txt", "w")
for item in sl:
f.write(item)
f.close()
mainScreen()
if option == 1:
print("Please note: This code can only take up to 10 product sizes.")
products = int(input("How many products are there? "))
if products > 10:
print("This code can only take up to 10 product sizes.")
print("Please enter only up to 10 product sizes below.")
if products <= 1:
print("You must enter at least two product sizes to compare.")
if products >= 1:
cost1 = float(input("Cost of first product($): "))
mass1 = float(input("Mass of first product(g): "))
ans1 = cost1/mass1
a = ans1
ans2 = ""
ans3 = ""
ans4 = ""
ans5 = ""
ans6 = ""
ans7 = ""
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 2:
cost2 = float(input("Cost of second product($): "))
mass2 = float(input("Mass of second product(g): "))
ans2 = cost2/mass2
if a > ans2:
a = ans2
if products >= 3:
cost3 = float(input("Cost of third product($): "))
mass3 = float(input("Mass of third product(g): "))
ans3 = cost3/mass3
if a > ans3:
a = ans3
ans4 = ""
ans5 = ""
ans6 = ""
ans7 = ""
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 4:
cost4 = float(input("Cost of fourth product($): "))
mass4 = float(input("Mass of fourth product(g): "))
ans4 = cost4/mass4
if a > ans4:
a = ans4
ans5 = ""
ans6 = ""
ans7 = ""
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 5:
cost5 = float(input("Cost of fifth product($): "))
mass5 = float(input("Mass of fifth product(g): "))
ans5 = cost5/mass5
if a > ans5:
a = ans5
ans6 = ""
ans7 = ""
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 6:
cost6 = float(input("Cost of sixth product($): "))
mass6 = float(input("Mass of sixth product(g): "))
ans6 = cost6/mass6
if a > ans6:
a = ans6
ans7 = ""
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 7:
cost7 = float(input("Cost of seventh product($): "))
mass7 = float(input("Mass of seventh product(g): "))
ans7 = cost7/mass7
if a > ans7:
a = ans7
ans8 = ""
ans9 = ""
ans10 = ""
if products >= 8:
cost8 = float(input("Cost of eighth product($): "))
mass8 = float(input("Mass of eighth product(g): "))
ans8 = cost8/mass8
if a > ans8:
a = ans8
ans9 = ""
ans10 = ""
if products >= 9:
cost9 = float(input("Cost of ninth product($): "))
mass9 = float(input("Mass of ninth product(g): "))
ans9 = cost9/mass9
if a > ans9:
a = ans9
ans10 = ""
if products >= 10:
cost10 = float(input("Cost of tenth product($): "))
mass10 = float(input("Mass of tenth product(g): "))
ans10 = cost10/mass10
if a > ans10:
a = ans10
if products >= 1:
print("The product(s) with the best value is/are the below product number(s):")
if ans1 == a:
print(1)
if ans2 == a:
print(2)
if ans3 == a:
print(3)
if ans4 == a:
print(4)
if ans5 == a:
print(5)
if ans6 == a:
print(6)
if ans7 == a:
print(7)
if ans8 == a:
print(8)
if ans9 == a:
print(9)
if ans10 == a:
print(10)
print("The cost per gram is $", a, "/ g")
print("If there are multiple options above, choose the one with best quality.")
if option == 2:
p = float(input('The ticket (original) price($): '))
d = float(input('The discount(%): '))
s = (d*0.01)
ps = (p*s)
answer = (p - ps)
answer2 = str(round(answer, 2))
print('The discount is $', ps)
print('The final price is $', answer2)
if option == 3:
o = float(input('The ticket (original) price($): '))
d = float(input('Price after the discount($): '))
p = 100/(o/d)
p = str(round(p, 2))
print('The percentage discount is', p,'%')
if option == 5:
exit = input("Are you sure you want to exit? (Yes/No): ")
if exit == "yes":
print("Thank you and goodbye!")
cont = 'no'
if exit == "Yes":
print("Thank you and goodbye!")
cont = 'no'
if exit == "YES":
print("Thank you and goodbye!")
cont = 'no'
elif option != 1:
if option != 2:
if option != 3:
if option != 4:
if option != 5:
print('Invalid input')
cont = input('Continue? (Yes/No): ')
if cont == 'No':
print("Thank you and goodbye!")
if cont == 'no':
print("Thank you and goodbye!")
if cont == 'NO':
print("Thank you and goodbye!")
Comments