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 add_pepperoni == "Y":
        if extra_cheese == "Y":
            
            print(f"Your final bill is:  {price_s + pep_sp + extra_cheese}")
        elif add_pepperoni == "N":
            if extra_cheese == "Y":
                print(f"Your final bill is: {price_s + extra_cheese}")
            elif add_pepperoni == "Y":
                if extra_cheese == "N":
                    print(f"Your final bill is: {price_s + pep_sp}")
                else:
                    print(f"Your final bill is: {price_s}")

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.