2

Python newbie here, unsure if this is the correct method but i'm having issues when trying to get the following to run:

from Meal_Options import usual_meals, healthy_meals, hot_meals, other_meals, lunch_meals, fast_food_meals print("Hello! Lets decide what you want for lunch! Please answer the first question.") lunch_tea = input("Is it lunch, or tea? ").lower() if lunch_tea == "lunch": print(*lunch_meals, sep="\n") elif lunch_tea == "tea": healthy = input("Healthy or not healthy? ").lower() if healthy == "healthy": food_type = input("Do you want spicy or not spicy? ").lower if food_type == "not spicy": print(*healthy_meals, sep="\n") print(*usual_meals, sep="\n") print(*other_meals, sep="\n") elif food_type == "spicy": print(*hot_meals, sep="\n") elif healthy == "not healthy" or "unhealthy": pizza_chinese_indian = input("Do you want pizza, chinese or indian? ").lower if pizza_chinese_indian == "pizza": print(*fast_food_meals) elif pizza_chinese_indian == "chinese": print(*fast_food_meals) elif pizza_chinese_indian == "indian": print("Ok, Korma it is") elif lunch_tea != "tea" or "lunch": print("\n" "Invalid input, please enter 'Tea' or 'Lunch'") finished = input("Are you happy with your selection? ").lower 

Output:

Hello! Lets decide what you want for lunch! Please answer the first question. Is it lunch, or tea? tea Healthy or not healthy? not healthy Do you want pizza, chinese or indian? chinese Are you happy with your selection? no 

Why does the code not print anything when answering "pizza", "chinese" or "indian" and just moves onto "Are you happy with your selection?"

1
  • try again ... this time answer unhealthy Commented Feb 25, 2021 at 17:21

3 Answers 3

2

Your second argument or "lunch" will always evaluate to True since it's a string of a non-zero length.

Should be

elif lunch_tea != "tea" or lunch_tea != "lunch": 

or, even better:

elif lunch_tea not in ("tea", "lunch"): 
Sign up to request clarification or add additional context in comments.

Comments

1

I believe the main issue here is that you are forgetting to add the () after the str.lower method.

from Meal_Options import usual_meals, healthy_meals, hot_meals, other_meals, lunch_meals, fast_food_meals ... if lunch_tea == "lunch": print(*lunch_meals, sep="\n") elif lunch_tea == "tea": ... if healthy == "healthy": food_type = input("Do you want spicy or not spicy? ").lower() ... elif healthy == "not healthy" or "unhealthy": pizza_chinese_indian = input("Do you want pizza, chinese or indian? ").lower() ... ... finished = input("Are you happy with your selection? ").lower() 

I've copied only the relevant code in order to highlight exactly where the issues are.

Comments

1

you probably want in or to have something like

if healthy == "not healthy" or healthy == "unhealthy" 

The problem is that you're forming a structure like

if healthy == "not healthy" or "unhealthy" if (var == test) or (True): 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.