Basically, yes. though your indentation is off. All of your 'if' become 'elif' with the 'else' statement being the failsafe should all else fail.
While we're at it, this = not good
def menu(): print("l – load file of movie titles"'\n'"r – random movie"'\n'"s– search"'\n'""
"sw – starts with"'\n'"k – keep - save the last displayed movie title to your favourites"'\n'"f – favourites display"'\n'""
"c – clear"'\n'"q - quit program")
this = better
def menu():
print("l – load file of movie titles\nr – random movie\ns– search\nsw – starts with\n"
"k – keep - save the last displayed movie title to your favourites\nf – favourites display\nc – clear\n"
"q - quit program")
This = bad
l = file = open("C:\\Users\\LiquidO\\Desktop\\Assingment 2 python\\movies.txt", "r")
if selection =='l':
movies_list = file.readlines()
movies_list = [movie.strip() for movie in movies_list]
print("Movies now loaded")
Why assign to a variable 'l' plus you must manually close the file
This = better
if selection == 'l':
with open("C:/Users/LiquidO/Desktop/Assignment 2 python/movies.txt", "r") as file:
movies_list = file.readlines()
movies_list = [movie.strip() for movie in movies_list]
print("Movies now loaded")
File will be closed automatically.
Why assign a print function to 'r', and not use 'r'? Just print it.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition