Jul-17-2020, 11:16 PM
And just for reference, this is how I imagined the solution. Main points are: to use the while loop instead of recursively calling add_to_lp_list() (the function calls itself - in most cases it's bad practice). Using globals is also a considered bad practice. Prefer passing arguments to functions instead (in the following code it's finalize_lp_list(lp_list), which calls def finalize_lp_list(unsorted_list)
import time def add_to_lp_list(): #####This should loop until you decide you are ready add = "start" lp_list = [] #####This is not the final list, but a list where you add everything to be sorted while add != "done": print("Artist: Album (or type \"done\" if you have finished the list)") add = input() if add == "done": finalize_lp_list(lp_list) elif add == "": print("Input empty, discarding.") else: print("Is this correct? " + add) print("Press Enter to confirm, typing anything else will discard.") answer = input() if answer == "": lp_list.append(add) else: print("Discarding last.") def finalize_lp_list(unsorted_list): lp_list_sorted = sorted(unsorted_list) ####This list is the final product, with everything sorted lp_list_final = lp_list_sorted with open("LP_list.txt", 'w') as output_file: for item in lp_list_final: output_file.write(item + "\n\n") print("List is now in the text file.") time.sleep(10) exit() ####Actual add_to_lp_list()