def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ menu = ['Display albums list', 'Delete album', 'Add album', 'Get albums by genre', 'Display oldest album', 'Display oldest album in selected genre' 'Show genre statistics', 'Display longest album', 'Display total albums lenght' ] albums = file_handling.import_data() while True: display.print_command_result('Welcome in albums database app') display.print_command_result('Select an option') display.print_program_menu(menu)
def menu_options(): # options = ["Exit", "Delete album", "Get Albums by genre", "Display oldest album", "Show genre stats"] options = [ "Exit", "Get Albums by genre", "Get longest album", "Show total albums length" ] display.print_program_menu(options)
def option_7(): print("This is the shortest Album:") shortest() spaceline() print("This is the longest Album:") longest() spaceline() print("These are the Last Releasead Albums from the Library:") youngest() spaceline() print("These are the First Releasead Albums from the Library:") oldest() spaceline() print(f"There are {howmanyalbums()} albums in the Library") howmanyalbums() spaceline() print("How many albums by genre:") howmanyalbumgivethegenres() spaceline() a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü()
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ print_command_result('MUSIC LIBARY \n') while True: global file_albums global MENU print_command_result('Menu\n') print_program_menu(MENU) print('___________________________________________________\n') user_input =input('Please chose one of teh following option:') if user_input =='1': print_command_result('LIST OF ALBUMS\n') print_albums_list(file_albums) elif user_input =='2': genre = input('Enter a music genre: ') gen_albums = get_albums_by_genre(file_albums, genre) print_command_result('all of the file data\n') print_albums_list(gen_albums) elif user_input=='3': genre =input('Enter genre: \n') last_oldest_by_gen = get_last_oldest_of_genre(file_albums,genre) print_command_result('Oldest album of chosen genre:\n') print_album_info(last_oldest_by_gen) elif user_input =='4': longest_album = get_longest_album(file_albums) print_command_result('Longest album is:\n') print_album_info(longest_album) elif user_input =='5': lenght_f_album = get_total_albums_length(file_albums) print_command_result('"Total albums lenght is(float):\n"') print_command_result(str(lenght_f_album)) elif user_input =='6': year = input("Enter choosen year: ") album_years = get_album_by_year(file_albums,year) print_command_result('Album chosen by year\n') print_albums_list(album_years) elif user_input =='7': last_oldest = get_last_oldest(file_albums) print_command_result('oldest album\n') print_albums_list(last_oldest) elif user_input =='8': genre_stat =get_genre_stats(file_albums) print_command_result('Statistic\n') print_album_info(genre_stat) elif user_input =='9': break else: continue
def main(): # importuje plik i zapisuje w lokalnej dla tego modułu liście albums_data = file_handling.import_data("albums_data.txt") working = True check = True text = "" # loopa zeby menu było wyświetlane non stop, nawet jesli ValueError to znaczy jesli input # nie bedzie int. text jest po to zeby wyswietlac okreslony komunikat w dowolnie wybranym miejscu # w przypadku dobrze wybranej opcji zamieniam text na pusty string zeby komunika nie byl wysiwetlany while working and check: try: display.print_program_menu([ "Show table", "Delete album", "Display oldest album", "Get albums by genre", "What is the oldest album by genre", "For arrow keys navigation" ], text) choice = int(input("What is your choice?:")) if choice == 1: display.print_albums_list(albums_data) display.pause() text = "" elif choice == 2: display.print_albums_list(albums_data) artist = input("What is name of artist you want to delete: ") album_name = input( "What is name of album you want to delete: ") delete_album_by_artist_and_album_name(albums_data, artist, album_name) text = "" elif choice == 3: display.print_command_result( music_reports.get_last_oldest(albums_data)) text = "" elif choice == 4: try: genre = input("What is the genre?: ") display.print_albums_list( music_reports.get_albums_by_genre(albums_data, genre)) display.pause() text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif choice == 5: try: genre = input("What is the genre?: ") display.print_command_result( music_reports.get_last_oldest_of_genre( albums_data, genre)) text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif choice == 6: arow_nawigation_menu() elif choice == 0: display.clear() working = False except ValueError: text = "\033[41;33mGive proper number\33[m"
def addsong(): addsong = input( "To add a song to the list press 'a'!\nTo go back to menu press 'q'!\n " ) if addsong == "a": writetotxt() os.system('clear') option_1() elif addsong == "q": os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_1()
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ is_program_working = True while is_program_working: display.print_program_menu(MAIN_MENU) try: choose_option() except ValueError as err: display.print_command_result(str(err))
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ os.system('clear') menu_options = [ 'Print albums list', 'Get_albums_by_genre', 'Get_longest_album', 'Get_total_albums_length' ] display.print_program_menu(menu_options) albums = file_handling.import_data() menu_option_choose(albums)
def option_3(): try: timerange(int(input('Shortest Time: ')), int(input('Longest Time: '))) spaceline() except: os.system('clear') print('You have to write integers! ') option_3() print('press any key if you want to give another range! ') a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_3()
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ options = ["Exit","Get albums of chosen genre", "Get longest album", "Get total albums length"] display.print_program_menu(options) albums = get_file() user_option = None while user_option != "0": user_option = get_option() do_option(user_option, albums) display.print_command_result("That's everything, thank you!")
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ choose = None while choose != 5: commands = [ 'Get albums by genre', 'Qunatity of albums in each genre', 'Get album with biggest value in length field', 'Get last album with earliest release year', 'Get last album with earliest release year in given genre', 'Exit' ] display.print_albums_list(albums) display.print_program_menu(commands) choose = int(input("Please provide your choose: ")) message = commands[choose] display.print_command_result(message) if message == 'Get albums by genre': genre = input("Pleae provide a music genre: ") albums_data = music_reports.get_albums_by_genre(albums, genre) for album in albums_data: display.print_album_info(album) if message == 'Qunatity of albums in each genre': result = music_reports.get_genre_stats(albums) message = str(result) display.print_command_result(message) if message == 'Get album with biggest value in length field': albums_data = music_reports.get_longest_album(albums) for album in albums_data: display.print_album_info(album) if message == 'Get last album with earliest release year': albums_data = music_reports.get_last_oldest(albums) for album in albums_data: display.print_album_info(album) else: print("dupas")
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should have main loop of program that will end only when user choose an option from menu to close the program. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ student_data = data.import_data_from_file('class_data.txt') while True: print("Hello to JERZYBOT. Please select Your option.") menu_commands = ["Create new student.", "Delete student.", "Select student.", "Print all students.", "Quit."] display.print_program_menu(menu_commands) while True: users_choice = input("Choose:") if users_choice not in ["0", "1", "2", "3", "4"]: print("Please choose correct number.") continue else: break if users_choice == "0": print("Create new student. Available soon!") if users_choice == "1": print("Delete student.") uid = input("Choose id: ") for line in student_data: if line[0] == uid: student_data.remove(line) if users_choice == "2": selected_student = input("Choose_student") for line in student_data: if line[0] == selected_student: print(" ".join(line)) if users_choice == "3": display.print_students_list(student_data) if users_choice == "4": quit() display.print_command_result(users_choice)
def option_4(): shortlonglist = ['shortest album', 'longest album'] display.print_program_menu(shortlonglist) spaceline() option = int(input('Choose from the options: ')) spaceline() if option == 1: shortest() spaceline() print('press any key if you want to go back: ') a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_4() elif option == 2: longest() spaceline() print('press any key if you want to go back: ') a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_4() else: os.system('clear') option_4()
def progressmenü(): option = int(input('Choose from the options: ')) os.system('clear') if option == 1: option_1() elif option == 2: option_2() elif option == 3: option_3() elif option == 4: option_4() elif option == 5: option_5() elif option == 6: option_6() elif option == 7: option_7() elif option == 8: option_8() else: display.print_program_menu(menu) progressmenü()
def option_2(): lg = [] for i, q, t, g, z in openfile('text_albums_data.txt'): lg.append(g) sg = set(lg) lg = list(sg) display.print_program_menu(lg) spaceline() try: albumbydata(3, lg[int(input('Choose one option: ')) - 1]) spaceline() except: os.system('clear') option_2() print('press any key to go back to genres! ') a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_2()
def option_6(): lq = [] for i, q, y, g, t in openfile('text_albums_data.txt'): lq.append(q) sq = set(lq) lq = list(sq) display.print_program_menu(lq) spaceline() try: albumbydata(1, lq[int(input('Choose one option: ')) - 1]) spaceline() except: os.system('clear') option_2() print('Press any key if you want to go back! ') a = input("Press 'q' to back to main menu : ") if a == 'q': os.system('clear') display.print_program_menu(menu) progressmenü() else: os.system('clear') option_6()
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ menu_commands = [ "Delete album", "Get albums by genre", "How many albums are in each genre", "Get last album with earliest release year", "Get last album with earliest release year in given genre", "Get longest album", "Get sum of lengths of all albums in minutes", "Quit program" ] while True: albums_data = file_handling.import_data(filename='albums_data.txt') display.print_command_result("Choose your option:") display.print_program_menu(menu_commands) choice = input("What would you like to do? ") if choice == "0": display.print_albums_list(albums_data) artist = input("Which artist would you like to remove?") album_name = input("Which album would you like to remove?") delete_album_by_artist_and_album_name(albums_data, artist, album_name) elif choice == "1": genre = input("Which genre would you like to check?") try: genre_list = music_reports.get_albums_by_genre( albums_data, genre) display.print_albums_list(genre_list) except ValueError: display.print_command_result("Wrong genre does not match") elif choice == "2": message = str(music_reports.get_genre_stats(albums_data)) display.print_command_result(message) elif choice == "3": oldest = music_reports.get_last_oldest(albums_data) display.print_album_info(oldest) elif choice == "4": genre = input("Which genre would you like to check?") try: oldest_from_genre = music_reports.get_last_oldest_of_genre( albums_data, genre) display.print_album_info(oldest_from_genre) except ValueError: display.print_command_result("Wrong genre does not match") elif choice == "5": longest = music_reports.get_longest_album(albums_data) display.print_album_info(longest) elif choice == "6": message = str(music_reports.get_total_albums_length(albums_data)) display.print_command_result(message) elif choice == "7": sys.exit() else: display.print_command_result("There's no such option. Try again.")
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should have main loop of program that will end only when user choose an option from menu to close the program. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ menu_commands = [ "Delete student.", "Get student by unique id.", "Get all students from given class.", "Get youngest student from all classes.", "Get youngest student from given class", "Get oldest student from all classes", "Get oldest student from given class", "Calculate average grade of all students", "Calculate average presence of all students", "Add new student.", "Get all students with given gender", "Sorts student list by age", "Update student", "Exit program." ] while True: table = data.import_data_from_file(filename='class_data.txt') display.print_command_result("") display.print_program_menu(menu_commands) answer = input("Hello to JERZYBOT. Please selcect your option:") if answer == "0": display.print_students_list(table) is_in_table = True while is_in_table: uid = input("Which student would you like to erase(id)? ") for row in table: if row[0] == uid: is_in_table = False delete_student_by_id(table, uid) elif answer == "1": display.print_students_list(table) uid = input("Which student would you like to check? ") try: student_data = data.get_student_by_id(uid, table) display.print_student_info(student_data) except ValueError: display.print_command_result('Student does not exist') elif answer == "2": class_name = get_class_from_user() student_data = data.get_students_of_class(table, class_name) display.print_students_list(student_data) elif answer == "3": student_data = data.get_youngest_student(table) display.print_student_info(student_data) elif answer == "4": class_name = get_class_from_user() student_data = data.get_youngest_student_of_class( table, class_name) display.print_student_info(student_data) elif answer == "5": student_data = data.get_oldest_student(table) display.print_student_info(student_data) elif answer == "6": class_name = get_class_from_user() student_data = data.get_oldest_student_of_class(table, class_name) display.print_student_info(student_data) elif answer == "7": message = str(data.get_average_grade_of_students(table)) display.print_command_result(message) elif answer == "8": message = str(data.get_average_presence_of_students(table)) display.print_command_result(message) elif answer == "9": new_student = [] question = [ "name: ", "surname: ", "year of birth: ", "class: ", "average grade: ", "average presence: " ] display.print_command_result("Please provide:") for item in question: new_student.append(input(item)) add_new_student(table, new_student) elif answer == "10": try: gender = input( "Which gender would you like to check (female/male)?") student_data = data.get_all_by_gender(table, gender) display.print_students_list(student_data) except ValueError: print('Wrong gender') elif answer == "11": try: order = input("Which order you choose(asc, desc, None)? ") if len(order) == 0: order = None student_data = data.sort_students_by_age(table, order) display.print_students_list(student_data) except ValueError: display.print_command_result("Wrong order") elif answer == "12": display.print_students_list(table) is_in_table = True while is_in_table: uid = input("Which student would you like to update(id)? ") for row in table: if row[0] == uid: is_in_table = False new_student = [] question = [ "name: ", "surname: ", "year of birth: ", "class: ", "average grade: ", "average presence: " ] display.print_command_result("Please provide:") for item in question: new_student.append(input(item)) update_student(table, uid, new_student) elif answer == "13": sys.exit() else: display.print_command_result("There's no such option. Try again.")
def main(): """ Calls all interaction between user and program, handles program menu and user inputs. It should repeat displaying menu and asking for input until that moment. You should create new functions and call them from main whenever it can make the code cleaner """ menu = [ 'Get album by genre.', 'Get genre stats.', 'Get longest album.', 'Get last album with earliest release year by genre', 'Get sum of lengths of all albums in minutes', 'Delete album.' ] albums = file_handling.import_data() while True: display.print_program_menu(menu) try: option = int(input('Enter option number: ')) os.system('cls') if option == 0: try: genre = input('Enter genre: ') result = music_reports.get_albums_by_genre(albums, genre) display.print_albums_list(result) except: display.print_command_result('Genre not found!') elif option == 1: result = music_reports.get_genre_stats(albums) print(result) elif option == 2: result = music_reports.get_longest_album(albums) display.print_album_info(result) elif option == 3: try: genre = input('Enter genre: ') result = music_reports.get_last_oldest_of_genre( albums, genre) display.print_album_info(result) except: display.print_command_result('Genre not found!') elif option == 4: result = music_reports.get_total_albums_length(albums) display.print_command_result(str(result)) elif option == 5: display.print_albums_list(albums) artist = input('Enter artist name: ') album_name = input('Enter album_name: ') result = delete_album_by_artist_and_album_name( albums, artist, album_name) display.print_albums_list(result) else: print('Option not found') except ValueError: print('Enter only number!')