(SCHOOL ASSIGNMENT) Help don't know why my code is printing both strings

Question:
When the user asks for one of the menu items its prints what is supposed to be printed for that input and also prints the else statement for if they did not inputted an invalid item that is not on the menu
Repl link:

code snippetTotal_Cost = 0.0
order = input(
  "Welcome to Wendy's! What can I get started for you? We have Chicken, beef, and tofu sandwiches.")
if order == "tofu":
  Total_Cost = Total_Cost + 5.75 and print("one tofu sandwhich coming up!")
if order == "beef":
  Total_Cost = Total_Cost + 6.25 and print("one beef sandwhich coming up!")
elif order == "chicken":
  Total_Cost = Total_Cost + 5.25 and print("one chicken sandwhich coming up!")
else: repeat = input("I dont think thats on the menu. Would you like me to repeat what we have?")
if repeat == "yes":
 order = input("We have Chicken, beef, and tofu sandwiches what would you like?")

This seems like a school assignment. We don’t usually give solutions with those problems directly, but we can help you guide you in the right direction.

So here’s a hint: You asked for a repeat only if the user inputted an invalid food item. You need to find a way to ask a repeat every time the user has inputted something.

2 Likes

Maybe try a little continue at the end :wink:

Yeah my friend in my computer science class was saying I need to do that and im assuming with some kind of loop but I have never done a loop before

continue wouldn’t work as it’s not in a loop here

1 Like

I was trying to not give the whole answer. :rofl:

Hello there.
The issue with the code is that the else statement and the if statement for checking if the user wants to repeat the order are not properly indented. Therefore, they are not part of the if statement checking for valid menu items.

Here’s the corrected code:

Total_Cost = 0.0
order = input("Welcome to Wendy's! What can I get started for you? We have Chicken, beef, and tofu sandwiches.")

if order == "tofu":
  Total_Cost = Total_Cost + 5.75 
  print("one tofu sandwich coming up!")
elif order == "beef":
  Total_Cost = Total_Cost + 6.25 
  print("one beef sandwich coming up!")
elif order == "chicken":
  Total_Cost = Total_Cost + 5.25 
  print("one chicken sandwich coming up!")
else: 
  repeat = input("I dont think thats on the menu. Would you like me to repeat what we have?")
  if repeat == "yes":
    order = input("We have Chicken, beef, and tofu sandwiches what would you like?")

Now, the else statement is properly associated with the if statement checking for valid menu items, and the code for repeating the order is properly nested within the else statement.

1 Like

Please don’t give the direct answer for school assignments.

We would love to help others who don’t know how to find a way to their problems, but for situations such as this, we want them to learn and understand the concepts by guiding them instead of just allowing them to copy and paste the answers.

1 Like