def main(): """ Main function with command loop """ current_file = "" while True: print(chr(27) + "[2J" + chr(27) + "[;H") input_text = menu.show_menu(current_file) choice = input(input_text) if choice == "quit": break elif choice == "change": current_file = "" elif choice == "lines": analyzer.lines(current_file) elif choice == "words": analyzer.words(current_file) elif choice == "letters": analyzer.letters(current_file) elif choice == "word_frequency": analyzer.word_frequency(current_file) elif choice == "letter_frequency": analyzer.letter_frequency(current_file) elif choice == "all": analyzer.all(current_file) elif not current_file: current_file = choice else: print(choice + " matchar inget val") print() input("Tryck enter för att komma vidare") sys.exit(0)
def main(): """ runs menu and functions """ while True: menu.menu_here() choice = input() choice.lower() if choice == "q": print("Bye Bye") break elif choice == "lines": print() print("Number of lines: " + str(analyzer.lines())) print() elif choice == "words": print() print("Number of words: " + str(analyzer.word_count())) print() elif choice == "letters": print() print("Number of letters: " + str(analyzer.letters())) print() elif choice == "word frequency": print() analyzer.word_frequency() print() elif choice == "letter frequency": print() analyzer.letter_frequency() print() elif choice == "all": analyzer.do_all() elif choice == "change": print(analyzer.change()) else: print("You inserted something strange")
def main(): """ Generates the menu throug an eternal loop. It checks the choice done by the user and calls the appropriate function. Loop breaks when q is the user input. """ menu.generate_menu() result = "" while True: choice = input("--> ") if choice == "q": quit() elif choice == "lines": result = analyzer.lines() elif choice == "words": result = analyzer.words() elif choice == "letters": result = analyzer.letters() elif choice == "word_frequency": result = analyzer.word_frequency() elif choice == "letter_frequency": result = analyzer.letter_frequency() elif choice == "all": result = analyzer.all_analyzes() elif choice == "change": analyzer.change() else: print( "That is not a valid choice. You can only choose from the menu." ) analyzer.pretty_print(result) result = ""
def analyze_all(user_input=None): """ Displaying all the menus. """ res_dict = {} if not user_input: print("all: Analysera filen") elif user_input: res_lines = analyzer.lines(user_input) # print("Antalet icke-tomma rader:", res_lines) res_words = analyzer.words(user_input) # print("\nAntalet ord:", res_words) res_letters = analyzer.letters(user_input) # print( # "\nAlla tecken förutom rader:", res_letters[0], # "\nAntal bokstäver:", res_letters[1] # ) res_word_freq = analyzer.word_frequency(user_input) # print("\nSju högsta förekommande orden:") # for value, key in res_word_freq[0][:7]: # print( # key, round(value / res_word_freq[1] * 100, 2), "%" # ) res_lett_freq = analyzer.letter_frequency(user_input) # print("\nSju högsta förekommande bokstäverna:") # for value, key in res_lett_freq[0][:7]: # print( # key, round(value / res_lett_freq[1] * 100, 2), "%" # ) empty_rows()
elif user_input.endswith(".txt"): filename = user_input file_not_found = analyzer.check_file_exists(filename) while True: if file_not_found: break menu.file() user_input = input("Välj ett val " + "(" + filename + "): ") if user_input == "quit": quit = True break elif user_input == "lines": analyzer.lines(filename) press_enter() elif user_input == "words": analyzer.words(filename) press_enter() elif user_input == "letters": analyzer.letters(filename) press_enter() elif "word_frequency" in user_input or "wf" in user_input: analyzer.word_frequency(filename) press_enter() elif "letter_frequency" in user_input or "lf" in user_input: