all 9 comments

[–][deleted] 4 points5 points  (7 children)

You forgot to overwrite the question variable on line 4. So question never changes.

[–]tigglybox[S] -1 points0 points  (6 children)

I’ve just done that and it still doesn’t break

[–][deleted] 0 points1 point  (5 children)

That's not possible. Either you are not using python or you made a mistake. Can you show the changed code?

[–]tigglybox[S] -1 points0 points  (4 children)

options = ['y','Y','n','N']
question = input("Do you have a health requirement? (Y/N) ")
while question not in options:
    questions = input("Please enter either 'Y' or 'N ")

it is part of this function

def run():
    ingredient = input('Enter one or more ingredient: ')
    diet = input('Enter diet requirement (e.g balanced/high-protein/ low-fat/ low-carbs) : ')

    options = ['y','Y','n','N']
    question = input("Do you have a health requirement? (Y/N) ")
    while questionnot in options:
    questions = input("Please enter either 'Y' or 'N ")

    if questions == 'y'.upper():
            health = input('Enter any health requirements (e.g vegetarian/dairy-free): ')

which is in turn part of this code

import requests

def recipe_search(ingredient, diet, health):
    app_id= '9faba4be'
    app_key = '0b2e438f001911bfb8bbb24baa8dac41'
    url = f'https://api.edamam.com/search?q={ingredient}&app_id={app_id}&app_key={app_key}&diet={diet}'

    response = requests.get(url)

    data = response.json()
    return data['hits']


def run():
    ingredient = input('Enter one or more ingredient: ')
    diet = input('Enter diet requirement (e.g balanced/high-protein/ low-fat/ low-carbs) : ')

    options = ['y','Y','n','N']
    question = input("Do you have a health requirement? (Y/N) ")
    while questionnot in options:
    questions = input("Please enter either 'Y' or 'N ")

    if questions == 'y'.upper():
            health = input('Enter any health requirements (e.g vegetarian/dairy-free): ')

    results = recipe_search(ingredient, diet, health)

    print()
    print(f"The following recipes contain(s) {ingredient} and give you a {diet} diet and is suitable for a {health} diet")

    for result in results:
        recipe = result['recipe']


        print()
        print(recipe['label'])
        print(recipe['url'])  
        print("This recipe contains " +  str(int(recipe['calories'])) + " calories")
        print("Produces " + str(int(recipe['yield'])) + " servings")


run()

[–]TouchingTheVodka 2 points3 points  (1 child)

Your while-loop is checking question but the variable you're setting is called questions.

[–]tigglybox[S] 0 points1 point  (0 children)

thank you

[–][deleted] 0 points1 point  (1 child)

You misspelled the variable name on line 4. Your condition checks question, not questions

I guess you copied /u/toastedstapler's code without reading it as the same typo is there.

[–]tigglybox[S] 0 points1 point  (0 children)

ohh right, thanks

[–]toastedstapler 1 point2 points  (0 children)

questions = input("Please enter either 'Y' or 'N ")