My code not printing output to console

``````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 ")

price_s = 15
price_m = 20
price_l = 25
pep_sp = 2
pep_mlp = 3
extra_cheese = 1

if size == "S":
if extra_cheese == "Y":

print(f"Your final bill is:  {price_s + pep_sp + extra_cheese}")
if extra_cheese == "Y":
print(f"Your final bill is: {price_s + extra_cheese}")
if extra_cheese == "N":
print(f"Your final bill is: {price_s + pep_sp}")
else:
``````

Iâ€™ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the â€śpreformatted textâ€ť tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Firstly, welcome to the forum.

As to your question, Iâ€™m not a Python guy, butâ€¦

You input a variable here:

``````extra_cheese = input("Do you want extra cheese? Y or N ")
``````

and then you change it here:

``````extra_cheese = 1
``````

So, since that will always be 1 by the time you get to your logic, your logic will never run - extra_chess can never be â€śYâ€ť or â€śNâ€ť. You need two variables.

I also think your logic can be cleaned up. If add_pepperoni is â€śYâ€ť, you need to check if itâ€™s â€śNâ€ť? Also, your nesting is confusing, I would assume that `if add_pepperoni == "Y":` was supposed to be on the same level of `elif add_pepperoni == "N":`, it makes even less sense if itâ€™s indented as it will always be false. If itâ€™s on the same level then it will always be true - at least if I understand Python indenting correctly. I also think that keeping a running total might be easier than calculating each branch separately, but thatâ€™s up to you.

Hi Kevin,
Thank you for the help and correct I was using variable cheese two times. It worked after correcting it.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.