from db import nederlandse_woorden import random import time RED = "\033[31m" GREEN = "\033[32m" BLUE = "\033[34m" RESET = "\033[0m" BOLD = "\033[1m" UNDERLINE = "\033[4m" YELLOW = "\033[33m" MAGENTA = "\033[35m" CYAN = "\033[36m" def start(aantal): print(BOLD + "Typ het woord over:" + RESET) print() woorden = random.sample(nederlandse_woorden, aantal) goed = 0 fout = 0 tijd_start_volledig = time.time() for woord in woorden: print(BOLD + YELLOW + woord + RESET) print() start_tijd = time.time() gegeven = input(" > " + UNDERLINE).strip() print(RESET) eind_tijd = time.time() tijd = round(eind_tijd - start_tijd, 2) if gegeven == woord: print(f"{GREEN}{BOLD}Goed! {RESET}Tijd: {tijd} seconden") print() goed += 1 elif gegeven == "exit": break elif gegeven == "quit": break elif gegeven == "break": break else: fout += 1 print(f"{RED}{BOLD}Fout!{RESET} Het juiste woord was: {woord}") print(f"Tijd: {tijd} seconden") print() tijd_stop_volledig = time.time() totale_tijd = round(tijd_stop_volledig - tijd_start_volledig, 2) gem_tijd = round(totale_tijd / len(woorden), 2) totaal = goed + fout accuracy = round((goed / totaal) * 100, 2) if totaal > 0 else 0 if accuracy >= 55: accuracy_kleur = GREEN else: accuracy_kleur = RED print() print(f"totaal goed: {GREEN}{BOLD}{goed}{RESET}") print(f"totaal fout: {RED}{BOLD}{fout}{RESET}") print(f"totale tijd: {MAGENTA}{BOLD}{totale_tijd}{RESET}") print(f"gemiddelde tijd per woord: {MAGENTA}{BOLD}{gem_tijd}{RESET}") print(f"accuracy: {accuracy_kleur}{BOLD}{accuracy}%{RESET}") menu = f""" bens typcurses {UNDERLINE}Menu:{RESET} 1. Start 100 woorden 2. Start 200 woorden 3. Start alle woorden 4. Start kies aantal woorden 5. {BOLD}Afsluiten{RESET} """ while True: print(menu) menu_keuze = input(" > ").strip() if not menu_keuze.isdigit(): print("Voer een nummer in.\n") continue menu_keuze = int(menu_keuze) if menu_keuze > 5 or menu_keuze < 1: print("gekozen optie bestaat niet, probeer opnieuw.\n") elif menu_keuze == 1: start(100) elif menu_keuze == 2: start(200) elif menu_keuze == 3: start(len(nederlandse_woorden)) elif menu_keuze == 4: start(int(input("hoeveel woorden? :"))) elif menu_keuze == 5: break