My below block of code is not working as expected. Reaching out to seek your help.
print("Thank you for choosing Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ? \n ")
Bill =0
if size == "S":
Bill+=15
print("The cost of the Pizza is $15")
add_pepperoni = input("Do you want pepperoni? Y or N \n")
if add_pepperoni == "Y":
Bill+=2
if size =="M":
Bill+=20
print("The cost of the Pizza is $20")
if size =="L":
Bill+=25
print("The cost of the Pizza is $25")
add_pepperoni = input("Do you want pepperoni? Y or N \n")
if size =="M":
if add_pepperoni =="Y":
Bill=+3
extra_cheese = input("Do you want extra cheese? Y or N \n")
if extra_cheese =="Y":
Bill+=1
print(f"Thank you for choosing Python Pizza Deliveries! Your final bill is ${Bill}:")
This code does not work well when i choose Medium or Large Pizza:)
Not a bad try, but there are fundamental errors in your code, such as: why do you have two lines that are asking about “pepperoni”, albeit at different costs?
Would it not be better to organize your code into two sections: Pizza and Toppings, maybe?
So:
# put any variable initialization up front
total = 0
size = False
add_pepperoni = False
extra_cheese = False
# first the pizza size and also; always check the user input
while not size:
size = input("Please choose S, M or L: ").upper()
# if you use the `.upper()` method, then the user does not need to bother about it
if size not in ("S", "M", "L"):
size = False
else:
if size == "S":
total += 15
elif size == "M":
total += 20
else: # there's only one other option
total += 25
# now the toppings
while not add_pepperoni:
...
… I’ll leave the detail (such as adding up the bill) and the rest of this to you, but do see how that would be better?
The block of code ain’t working well cause you ain’t using if... elif stmts. Try this… just added a bit of spice to play around with it but you can totally remove the while loop but remember to indent the whole code back to the left imagine if you intend to remove not to get indentation error again lol… also using switch is good might wonna check it out. Cheers
total_bill = 0 # Initialize the total bill
# set up a loop to always prompt for new orders until the client declines
while True:
print("Thank you for choosing Python Pizza Deliveries!")
Bill = 0
size = input("What size pizza do you want? S, M, or L?\n")
if size == "S":
Bill += 15
print(f"The cost of the pizza is ${Bill}")
add_pepperoni = input("Do you want pepperoni? Y or N\n")
if add_pepperoni == "Y":
Bill += 2
print(f"Bill is at {Bill}")
elif size == "M":
Bill += 20
print("The cost of the Pizza is $20")
add_pepperoni = input("Do you want pepperoni? Y or N\n")
if add_pepperoni == "Y":
Bill += 3
elif size == "L":
Bill += 25
print("The cost of the Pizza is $25")
add_pepperoni = input("Do you want pepperoni? Y or N\n")
if add_pepperoni == "Y":
Bill += 3
extra_cheese = input("Do you want extra cheese? Y or N\n")
if extra_cheese == "Y":
Bill += 1
total_bill += Bill # Add the current order's bill to the total
print(f"Your total bill for this order is ${Bill}.")
print(f"Your cumulative total is ${total_bill}.")
another_order = input("Do you want to place another order? Y or N\n")
if another_order != "Y":
print("Thank you for choosing Python Pizza Deliveries! See you soon")
break
print(f"Thank you for choosing Python Pizza Deliveries! Your final total bill is ${total_bill}.")
You have a simple but business-critical syntax problem Deepak, causing customers asking for a medium pepperoni Pizza to be very pleasantly surprised by their bill.