May-06-2017, 10:41 PM
You are repeating the same thing over and over again. Have the program do that for you. That's what loops are for.
The problem with favorite is a scope problem. The favorite you define in a function only exists in that function. That's its scope. It is not the same as any favorite you define outside the function. What you want to do is return the value from the function:
while True: choice = input('Pick a letter: ').lower() if choice == 'a': print('The first letter') elif choice == 'z': print('The last letter') elif choice == 'q': break else: print('Some other letter')Notice how I use lower. It's better to get it from the string you are lowering (the result of input) than to get it from the str class.
The problem with favorite is a scope problem. The favorite you define in a function only exists in that function. That's its scope. It is not the same as any favorite you define outside the function. What you want to do is return the value from the function:
def search(movie_list): keyword = input('Search keyword: ').lower() matches = [] for movie in movies_list: if keyword in movie.lower(): print(movie) matches.append(movie) return matchesFirst of all, notice how I pass movie_list as a parameter to the function. This is again about scope. That puts movie_list into the scope of the function. Note that I don't name things list or file. We have told you repeatedly that is a bad idea, and you haven't changed it. Those are keywords in Python, and if you change them it could mess up some other part of Python you are trying to make use of. Then I build a list of matches (as I showed you before), and return it from the function. When the function is called, it would look like this:
matches = search(movie_list)Then you have the matches in the scope of the while loop. You can then add items from it to the favorites list that you defined in that same scope.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures