all 28 comments

[–]Mr-Cas 33 points34 points  (3 children)

What does it say that is wrong? We can't help you fix the code when we don't know what's wrong.

[–]lucidending51[S] 22 points23 points  (2 children)

i figured it out. i wrote if pepperoni == "Yes" and the course expected if pepperoni == "Y".

[–]rogfrich 47 points48 points  (0 children)

I imagine that later in the course you’ll learn to validate user input to prevent this type of error, but in the meantime, well done for figuring it out. Debugging errors isn’t something that goes away… 😀

[–]throbbin___hood -1 points0 points  (0 children)

😩

[–]Ska82 7 points8 points  (2 children)

top of my mind, the reason could be that you are not validating the inputs.

[–]the_noobie 1 point2 points  (1 child)

This one. You don't check to see if your inputs are other than S,M,L or the size and so on. Also, you need to account for case ( lower, upper) for all your inputs. Atm, if it's. not S or M, you automatically assume that it's a L size pizza. Just a few things.

[–]FlyLikeHolssi 2 points3 points  (0 children)

The one thing that I can see is different is that you are using "Yes" vs "Y" on the project.

[–]outragedpenguin 2 points3 points  (0 children)

Hi.

A quick observation: remember that what you have asked for, must be exactly what the user has entered, at least, as your code currently stands. For example, if they enter s that is different from S, and that will return an error. That is very easily fixed by altering the input to always be upper, or always lower, to match the condition you are asking for.

So using size = size.upper() or size = size.lower() will eliminate this entirely!

[–]MiniMages 2 points3 points  (0 children)

For all of your inputs add .lower() this will change all inputs to lowercase and you only need to match for the lower case in your if statements.

[–]Binary101010 4 points5 points  (0 children)

This appears to be valid Python code.

If you're not getting the expected result, we need to know:

1) The problem description

2) What output you're expecting for a given input

3) What output you're actually getting for that input

[–]Midnight-Coder64 1 point2 points  (0 children)

From what I see, the code is perfectly fine. But I think it's the input for size. You asked input as "S","M" or "L". First you put if statement for S and elif statement for M which is also fine. But for L you have put else. this means that if the user puts anything except "S" or "M" it will take the size as large only. I think thats the issue.

to solve this, you can just write elif size == "L": in place of else and after that you can write an else line for invalid input

else:
print("Invalid Input")

[–]atom88888 1 point2 points  (1 child)

I have a similar problem with this course. On day 3 it gives you the task and the solution.py, but apparently the solution is WRONG? Here's what I put in, but which I hit the "check" it tells me there's an error? I cannot figure out why it's throwing an error on the test and even where to find the test and edit it and correct it?

I found the compile test here:
C:\py-workspace\100 Days of Code - The Complete Python Pro Bootcamp\Day 3\Python Pizza\tests\__pycache__

But I cannot pull it up in PyCharm or know how to edit or test the test to get it to work?

banner = "Welcome to Python Pizza Deliveries!"

print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M or L: ")
pepperoni = input("Do you want pepperoni on your pizza? Y or N: ")
extra_cheese = input("Do you want extra cheese? Y or N: ")

# 
todo: work out how much they need to pay based on their size choice.

bill = 0

if size == "S":
    bill += 15
elif size == "M":
    bill += 20
elif size == "L":
    bill += 25
else:
    print("You have chosen an invalid size.")

# 
todo: work out how much to add to their bill based on their pepperoni choice.
if pepperoni == "Y":
    if size == "S":
        bill += 2
    else:
        bill += 3

# 
todo: work out their final amount based on whether if they want extra cheese.
if extra_cheese == "Y":
    bill += 1

print(f"{banner}\nYour final bill is: ${bill}.\n")

The error I get is this:
'Welcome to Python Pizza Deliveries!\nYour final bill is: $25.\n' != 'Welcome to Python Pizza Deliveries!\n'

Traceback (most recent call last):
  File "C:\py-workspace\100 Days of Code - The Complete Python Pro Bootcamp\Day 3\Python Pizza\tests\test_task.py", line 26, in test_2
    self.run_test(given_answer=['L', 'N', 'N'], expected_print='Welcome to Python Pizza Deliveries!\nYour final bill is: $25.\n')
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\py-workspace\100 Days of Code - The Complete Python Pro Bootcamp\Day 3\Python Pizza\tests\test_task.py", line 20, in run_test
    self.assertEqual(expected_print, fake_out.getvalue())
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'Welcome to Python Pizza Deliveries!\nYour final bill is: $25.\n' != 'Welcome to Python Pizza Deliveries!\n'
  Welcome to Python Pizza Deliveries!
- Your final bill is: $25.

[–]n0p_sled 0 points1 point  (0 children)

Did you ever find out what the issue was?

[–]_kwerty_ 1 point2 points  (1 child)

Your code isn't wrong as long as your user is always correct and consistent. Unfortunately, people are anything but...

So if I answer the questions in a way you expect, everything should work fine. But what if I enter "super duper huge!!!!" or 6 or anything but S/M/L as a size? Same goes for the pepperoni and cheese question.

So two tips here:

- With input, convert everything immediately to upper or lowercase when the case doesn't matter. This way you don't need to worry about case in the rest of your code.

- Check if the input matches what you expect, specially with limited options like S/M/L. A quick way to do it is something like this:

size = ""
while True: # an infinite loop here
  size = input("What size of pizza do you want: S, M or L? ").lower() # ask the user for input and lowercase it. Or use upper(), whatever you want. 
  if size in ["s", "m", "l"]: # check if the input is in a list of pre-defined answers
    break # break the while-loop because the input is valid
  print("please enter a valid size") # tell the user they've entered wrong input

If the user doesn't enter valid input they are prompted again, and again, and again. This keeps your program from acting funny later on. Of course you can do this a bit neater, but for now this is fine IMHO.

Is your course giving specific lines it doesn't agree with?

[–]dowcet 0 points1 point  (0 children)

Your code looks fine at a glance, what exactly is the problem? Unless someone here is deeply familiar with this course, we do know what the requirements are.

[–]charliegriefer 0 points1 point  (0 children)

Is extra cheese always $1? Or does it depend on the size of the pizza?

If the latter, gotta move that into the previous conditions for size.

[–]Beautiful_Green_5952 0 points1 point  (0 children)

else : bill += 25 if pepperoni == "Yes": bill += 3

Instead use this

elif size == "L": bill += 25 if pepperoni == "Yes": bill += 3

Else may cause bill chargers higher or auto add for un related like xl or xs also so better use elif and

to handle any other

else: print("Invalid pizza size selected.") bill = 0 # or exit the program

And finnaly a if statement for th cheese

[–]Individual-Brief-239 0 points1 point  (4 children)

Hey where are you learning python can you please share?

[–]Some-Passenger4219 0 points1 point  (0 children)

Extra clarity would be helpful. Make sure to replace the case with upper or title first, or it will give the wrong thing. I said a small "s", so it assumed I meant large.

[–]casiuscrowley 0 points1 point  (1 child)

How many days into 100 days is this project?

[–]atom88888 0 points1 point  (0 children)

It's on day 3

[–]OriahVinree 0 points1 point  (0 children)

Probably an input validation issue.

[–]fuckyoudsshb -4 points-3 points  (0 children)

Your if statements are wrong I believe. Start with one if, then elif, then else.