+ 1

Can anyone determine the problem..!?

print("Thank you for choosing Python Pizza Deliveries!") size = input() # What size pizza do you want? S, M, or L add_pepperoni = input() # Do you want pepperoni? Y or N extra_cheese = input() # Do you want extra cheese? Y or N # 🚨 Don't change the code above 👆 # Write your code below this line 👇 S = 15 M = 20 L = 25 Y_P = 3 Y_CH = 1 N_P = 0 N_CH = 0 Total1_s = S + Y_P + Y_CH Total2_s = S + Y_P Total3_s = S + Y_CH Total4_s = S if size == "S" : if add_pepperoni == "Y": if extra_cheese == "Y": print(f"Your final bill is: ${Total1_s}.") elif size == "S" : if add_pepperoni == "Y": if extra_cheese == "N": print(f"Your final bill is: ${Total2_s}.") elif size == "S" : if add_pepperoni == "N": if extra_cheese == "Y": print(f"Your final bill is: ${Total3_s}.") elif size == "S" : if add_pepperoni == "N": if extra_cheese == "N": print(f"Your final bill is: ${Total4_s}.") else: print("sorry, you can`t odder")

12th Nov 2023, 3:27 PM
Ibraahim
4 Respostas
+ 8
Ibraahim , it would be helpful if you could give statement what the issue with your code is: some hints at a glance: > the code is only working for an input of pizza size `S` > the logic to calculate the price seems to be too complicated. try to simplify it first.
12th Nov 2023, 3:58 PM
Lothar
Lothar - avatar
+ 3
Ibraahim , you have done a really great job! no the code is running for all sizes and the extras. i have added the inputs that are required, also i commented out some not required code: https://code.sololearn.com/cp9Cnt07YXN9/?ref=app
14th Nov 2023, 8:33 PM
Lothar
Lothar - avatar
+ 1
this is the answer; bill = 0 if size == "S": bill += 15 if size == "M": bill += 20 if size == "L": bill += 25 if add_pepperoni == "Y": if size == "S": bill += 2 else: bill += 3 if extra_cheese == "Y": bill += 1 print (f"Your final bill is: ${bill}.")
13th Nov 2023, 7:03 AM
Ibraahim
0
Your code would look more understandable if you can simplify it. Instead of calculate all the possible cost combinations, you can streamline into something like this. Cost for different size Extra cost for pepperoni Extra cost for additional cheese Calculate the cost by each option, then you have the total cost.
13th Nov 2023, 1:14 AM
Wong Hei Ming
Wong Hei Ming - avatar