def request_choice_ticket(): ''' Request of ticket. Options: | P = Preferred | | N = Normal Service | | MD = Material Delivery | | R = Results | | G = Get Material | Parameter > None Return > ticket: string. ''' while True: try: show_ticket() ticket = input('Type the option: ') ticket = ticket.upper() if check_choice_ticket(ticket): return ticket else: clear_screen() print('Option Incorret! Try again.\n') ticket = request_choice_ticket() return ticket except KeyboardInterrupt: clear_screen() print('Quit application trought of option 4 in Menu! \n')
def multiple_choice(csv_file): clear_screen() global TOTAL while True: word_list = csv_to_list(csv_file) choices = set() if len(word_list) == TOTAL: end_program() spanish_word, english_answer = rand_word(word_list, length=len(word_list)) choices.add(english_answer) while len(choices) <= 3: choices.add( rand_word(word_list, spanish=False, length=len(word_list))) correct = False _ = time() while not correct: correct = ask_question(spanish_word, choices, english_answer, total=TOTAL) __ = time() TOTAL += 1 seconds = int(__ - _) difficulty(spanish_word, seconds)
def ask_question(word, choices, answer, total): """Prints out question prompt""" clear_screen() print(f'Translate: {word}') choices = randomize_choices(choices) option_number = 1 for choice in choices: print(f'\n {option_number}) {choice}') option_number += 1 response = ask_answer(answer, choices, total) return response
def check_validity(response, choices, answer): """Check if response is valid""" clear_screen() index = int(response) - 1 if index in range(4): response = choices[index] correctness = check_correctness(answer, response) return correctness else: print('Answer not valid. Enter 1, 2, 3 or 4.\n') return False
def find_difficulty(word): """A prompt asking the difficulty of each question""" difficulty = 0 while difficulty not in range(1, 6): try: difficulty = input('Rate difficulty from 1(EASY) to 5(HARD): ') difficulty = int(difficulty) if difficulty in range(1, 6): clear_screen() known_words = read_from_file(KNOWN_WORDS_LOCATION) known_words[difficulty].append(word) save_to_file(known_words, KNOWN_WORDS_LOCATION) except: difficulty = 0
def multiple_choice(): clear_screen() while True: csv_file = '100_words.csv' word_list = csv_to_list(csv_file) choices = set() word, answer = rand_row(word_list) choices.add(answer) while len(choices) <= 3: choices.add(rand_row(word_list, question=False)) correct = False while not correct: correct = ask_question(word, choices, answer) find_difficulty(word)
def request_choice_menu(): ''' Request of choice for menu. Options: | 1 - Emission Ticket | | 2 - Call Ticket | | 3 - Queue | | 4 - Quit | Parameter > None Return > choice: int. ''' while True: try: show_menu() choice = int(input('Type the option (Only numbers): ')) if check_choice_menu(choice): return choice else: clear_screen() print("Option Incorret! Try again.") choice = request_choice_menu() return choice except ValueError: # Case it isn't a number clear_screen() print("Option it isn't a number! Try again.\n") choice = request_choice_menu() return choice except KeyboardInterrupt: clear_screen() print('Quit application, trought of option 4 in Menu! \n')
def show_leaderboard(c): """Display the leaderboard with an optional username search function. Args: c: The cursor object. """ if user_binary_choice("Do you want to search by username"): username = f"%{get_username()}%" c.execute( """SELECT * FROM `leaderboard` WHERE `username` LIKE ? ORDER BY `scoretotal` DESC, `username` ASC""", [username]) else: c.execute("""SELECT * FROM `leaderboard`""") clear_screen() results = c.fetchall() lines = 0 while lines < len(results): print('/' + "¯" * 89 + '\\') print("| {:15} | {:10} | {:13} | {:11} | {:13} | {:10} |".format( 'Username', 'Date', 'Overall Score', 'Maths Score', 'English Score', 'NCEA Score')) for x in range(get_terminal_size().lines - 3): print("| {:15} | {:10} | {:13} | {:11} | {:13} | {:10} |".format( results[lines][0], results[lines][1], results[lines][5], results[lines][2], results[lines][3], results[lines][4])) lines += 1 if lines >= len(results): input("(enter to continue)") clear_screen() return while True: user_input = input("[q]uit, [n]ew page: ").lower() if user_input == 'q': clear_screen() return if user_input == 'n': clear_screen() break clear_line()
def main_menu(): """ Creates our main menu with possible options of spanish learning activites or list to learn. Function calls its self over and over until valid selection is made or user types in 'exit'. """ clear_screen() print("LANGUAGE LEARNING APP") print("(type 'exit' to end program)\n") print("\t1) Multiple Choice") print("\t2) Family") print("\t3) Change Language") print("\t4) Other") selection = validate(main_menu) # Selection Choices if selection == 1: multiple_choice.multiple_choice('dataFiles/100_words.csv') elif selection == 2: clear_screen() multiple_choice.multiple_choice('dataFiles/family.csv') elif selection == 3: # change_language() clear_screen() print("Multiple language options are coming soon!") sleep(1) main_menu() elif selection == 4: # other() clear_screen() print("Other features are coming soon!") sleep(1) main_menu() else: print('That\'s not a valid entry, please try again.') sleep(1) main_menu()
\ _\|_________| \ _\ \__\\__\ |__| |__||__| ||/__/ |__||__| |__||__| |__||__| /__)/__) /__//__/ /__//__/ /__//__/. .' '. '. (________)____) """) time.sleep(5) clear_screen() print(r""" _ ( ) H H _H_ .-'-.-'-. / \ | | | .-------'._ | / / '.' '. \ | \ \ @ @ / / | '---------'
def end_program(total): clear_screen() print(f'You got {total} questions right!') exit()
def start_app(): ''' This function is for start app, it use the user' choice and dicts auxilities. Parameter > choice: int. list_call_ticket: list. dict_number_ticket: dict. dict_row_ticket: dict. Return > None. ''' #First dict for add with ticket, second for append in row. dict_number_ticket = { 'ticket_P': 0, 'ticket_N': 0, 'ticket_MD': 0, 'ticket_R': 0, 'ticket_G': 0 } dict_row_ticket = {'1': [], '2': [], '3': [], '4': [], '5': []} list_call_ticket = [] choice = request_choice_menu() # Choice of menu while True: if choice == 1: clear_screen() choice_ticket = request_choice_ticket() # Choice of ticket dict_number_ticket, dict_row_ticket = emission_ticket( choice_ticket, dict_number_ticket, dict_row_ticket) # Save the emissions clear_screen() choice = request_choice_menu( ) # Choice of menu, again for contiue the menu elif choice == 2: clear_screen() dict_row_ticket, list_call_ticket = call_ticket( dict_row_ticket, list_call_ticket) choice = request_choice_menu() elif choice == 3: clear_screen() show_queue(dict_row_ticket) choice = request_choice_menu() elif choice == 4: # If have any in queue. clear_screen() if check_queue(dict_row_ticket): print('Have tickets waiting to be called! \n') else: break choice = request_choice_menu() # Quiting... clear_screen() print(''' End of Application! The called tickets was: ''') if len(list_call_ticket): for ticket in range(len(list_call_ticket)): print(list_call_ticket[ticket], end='-') else: print('No ticket called\n') print('\nArtur-Cavalcante') # End Function for initialize the app.
def clear_and_print(text): """Clears the screen and prints your choice of message""" clear_screen() print(text)
def clear_and_exit(): """Clears the screen and exits""" exit(clear_screen())
def end_program(): clear_screen() print(f'You got {TOTAL} questions right!') exit()
def end_program(): clear_screen() print(f'You got {total_answered} questions right!') exit()