I am writing a code to calculate the price of a sandwich and the sum of its parts. However, when the price of the ingredients is output, I often get 0 values or high values that make no sense. Can someone look at the last 14 lines of my code and tell me why my math isn't right? I've been working on this for 3+ hours and I can't figure it out. Thanks.
## Spencer Shample's Code
name_vendor = input('What is the name of the name of the vendor?\n')
## input the vendors name
while True:
if name_vendor.isnumeric():
name_vendor = input('Please enter the name of the vendor to continue.\n')
else:
break
price_loaf_bread = input('\nHow much does a loaf of bread cost?\n$')
## input loaf of bread price here
while True:
if price_loaf_bread.isnumeric() and int(price_loaf_bread) > 0:
break
else:
price_loaf_bread = input('Please enter the price of a loaf of bread to continue.\n$')
num_slices_bread_loaf = input('\nHow many slices in a loaf of bread?\n')
## input number of slices in a loaf of bread
while True:
try:
if int(num_slices_bread_loaf) < 1:
raise ValueError #this will send it to the print message and back to the input option
break
except ValueError:
num_slices_bread_loaf = input('You must have one or more slices of bread to make a sandwich! \nPlease enter the number of slices of bread on your sandiwch(es)\n')
price_cheese_per_lb = input('\nWhat is the price of swiss cheese per pound?\n$')
## price of cheese per lb
while True:
if price_cheese_per_lb.isnumeric() and int(price_cheese_per_lb) > 0 :
break
else:
price_cheese_per_lb = input('Please enter the price cheese per lb to continue.\n$')
num_slices_cheese = input('\nHow many slices in a pound of cheese?\n')
## number of slices of cheese in a lb
while True:
try:
if int(num_slices_cheese) < 1:
raise ValueError #this will send it to the print message and back to the input option
break
except ValueError:
num_slices_cheese = input('You must have one or more slices of cheese to make a sandwich! \nPlease enter the number of slices of cheese on your sandiwch(es)\n')
price_pastrami_per_lb = input('\nWhat is the price of pastrami per pound?\n$')
## price of pastrami per lb
while True:
if price_pastrami_per_lb.isnumeric() and int(price_pastrami_per_lb) > 1:
break
else:
price_pastrami_per_lb = input('Please enter the price pastrami per lb to continue.\n$')
num_slices_pastrami = input('\nHow many slices in a pound of pastrami?\n')
## number of slices of pastrami in a lb
while True:
try:
if int(num_slices_pastrami) < 1:
raise ValueError #this will send it to the print message and back to the input option
break
except ValueError:
num_slices_pastrami = input('You must have one or more slices of pastrami to make a sandwich!
\nPlease enter the number of slices of pastrami on your sandiwch(es)\n')
dollar_per_slice_bread = (int(price_loaf_bread) / int(num_slices_bread_loaf))
input_num_slices_bread_loaf = input('How many slices of bread are you using on your sandwich?\n')
total_price_bread = (int(dollar_per_slice_bread) * int(input_num_slices_bread_loaf))
dollar_per_slice_cheese = (int(price_cheese_per_lb) / int(num_slices_cheese))
input_num_slices_cheese = input('How many slices of cheese are you using on your sandwich?\n')
total_price_cheese = (int(dollar_per_slice_cheese) * int(input_num_slices_cheese))
dollar_per_slice_pastrami = (int(price_pastrami_per_lb) / int(num_slices_pastrami))
input_num_slices_pastrami = input('How many slices of pastrami are you using on your sandwich?\n')
total_price_pastrami = (int(dollar_per_slice_pastrami) * int(num_slices_pastrami))
print(f"\nThe cost of the bread is ${total_price_bread:.2f}\n")
print(f"\nThe cost of the cheese is ${total_price_cheese:.2f}\n")
print(f"\nThe cost of the pastrami is ${total_price_pastrami:.2f}\n")
total_cost_sandwich = (total_price_bread + total_price_cheese + total_price_pastrami)
num_sandiwches = input('How many sandwiches are you making?\n')
print(f"If you are making {num_sandiwches} sandiwches then the total cost per sandwich from {name_vendor} is ${total_cost_sandwich:.2f}." )