Skip to content
Advertisement

My function is terminating early – How to fix this?

What changes do I need to make to correct the logic and to allow it to run through the entire function?

I am trying to call a function but each time the function gets to the line where the user enters either ‘all’ or ‘category’ it stops working. What I am trying to do is to allow the user to enter either all or category and to have the program either display all recipes listed within the dictionary or for the program to only display recipes that meet the specified criteria (the category). Would someone be able to help point out where my codes logic is incorrect?

Please note that I am trying to call the view choice function and each time I enter either all or category it stops running, I just added the others so you can see what is being called.

JavaScript

Advertisement

Answer

The problem you’re having is that the decision.lower == 'all' branch is not triggering when you enter all.

You can use print debugging to help solve the mystery. Temporarily add something like:

JavaScript

This outputs:

JavaScript

Welp, you’re comparing a method to a string. That’s why it doesn’t match. You can then change it to run the method, print(decision.lower()), and verify that it’s correct.

Now you can modify the branch to if decision.lower() == 'all': and try again

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement