Dec-14-2018, 04:32 PM
I am now getting my inside loops to run indefinitely, why?
If I don't have the while loop at the beginning the other loops run as they should and stop. When I add the while and else statement, they run non-stop.
If I don't have the while loop at the beginning the other loops run as they should and stop. When I add the while and else statement, they run non-stop.
options = input() while options == 'y' or 'd' or 't': if options == 'y': print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit') print('\nChoose an option:') for key in movies: print('%s:' % key) i = 0 while i < len(movies[key]): print('\t%s, %s' % (movies[key][i], movies[key][i + 1])) i += 2 print() director_list = [] if options == 'd': print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit') print('\nChoose an option:') for key in movies: i = 1 while i < len(movies[key]): director_list.append(movies[key][i]) i += 2 set_director = sorted(set(director_list)) for director in set_director: print('%s:' % director) for year, value in sorted(movies.items()): if director in value: print('\t%s, %s' % (value[value.index(director) - 1], year)) print() title_list = [] if options == 't': print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit') print('\nChoose an option:') for key in movies: i = 0 while i < len(movies[key]): title_list.append(movies[key][i]) i += 2 set_title = sorted(set(title_list)) for title in set_title: print('%s:' % title) for year, value in sorted(movies.items()): if title in value: print('\t%s, %s' % (value[value.index(title) + 1], year)) print() else: if options == 'q': print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit') print('\nChoose an option:')