https://pastebin.com/1yAmveJ3 (at the beginning it’s not important what matters most is the last else)

#Модули from colorama import init from colorama import Fore, Back, Style import random #Код init() kana = list('アイウエオカキクケコサシスセソタチッテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン') test_kana = ['a','i','u','e','o','ka','ki','ku','ke','ko','sa','si','su','se','so','ta','ti','tsu','te','to','na','ni','nu','ne','no', 'ha','hi','fu','he','ho','ma','mi','mu','me','mo','ya','yu','yo','ra','ri','ru','re','ro','wa','wo','n'] num_symbols = 46 num_random = num_symbols - 1 isklucheniya = [] resultats={} while len(isklucheniya)!=num_symbols: num=random.randint(0,num_random) while num in isklucheniya: num=random.randint(0,num_random) if num in isklucheniya: continue else: print(Fore.MAGENTA + Back.BLACK + kana[num]+' def') ja=input(Fore.RED) if ja == test_kana[num]: print(Back.GREEN+'Правильно') rez = 1 isklucheniya.append(num) resultats.update({kana[num]:1}) else: print(Back.RED+'Неправильно') rez = -1 isklucheniya.append(num) resultats.update({kana[num]:1}) break else: print(Fore.MAGENTA+ Back.BLACK + kana[num]) ja=input(Fore.RED) if ja == test_kana[num]: print(Back.GREEN+'Правильно') resultats.update({kana[num]:1}) isklucheniya.append(num) else: print(Back.RED+'Неправильно') resultats.update({kana[num]:-1}) isklucheniya.append(num) else: f=open('sas.txt', 'a', encoding='utf-8') print(Back.YELLOW) print(Fore.RED) for i in resultats: otvets = i +':'+str(resultats[i]) print(otvets) f.write(otvets) f.close() 

Closed due to the fact that off-topic participants Enikeyschik , 0xdb , aleksandr barakin , mkkik , eri May 14 at 23:26 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Enikeyschik, 0xdb, mkkik
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The code should be given in the question itself - gil9red
  • Fixed but the link to just left - Dospayne2
  • Is the resultats not empty? - gil9red
  • yes it seems no, and otvets are output, but it is not written to the file - Dospayne2
  • And if you specify the full path, the file is created and filled? - gil9red

1 answer 1

gil9red thanks a lot

for the time being, I added a few lines

 #Модули from colorama import init from colorama import Fore, Back, Style import random import os import pickle #Код init() num_symbols = 0 isklucheniya = [] resultats={} hor = 0 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) path_to_kana = ROOT_DIR+ '\\kana.txt' path_to_otvetkana = ROOT_DIR+ '\\kana_otvet.txt' try: with open(path_to_kana, 'rb') as f: kana=pickle.load(f) except FileNotFoundError: print(Back.RED+'Не загруженны файлы каны') exit() try: with open(path_to_otvetkana, 'rb') as f: test_kana=pickle.load(f) except FileNotFoundError: print(Back.RED+'Не загруженны файлы ответов на кану') exit() for i in kana: num_symbols += 1 num_random = num_symbols - 1 print(Fore.CYAN+'Всё загруженно') #Основной код while len(isklucheniya)!=num_symbols: num=random.randint(0,num_random) while num in isklucheniya: num=random.randint(0,num_random) if num in isklucheniya: continue else: print(Fore.MAGENTA + Back.BLACK + kana[num]) ja=input(Fore.RED) if ja == test_kana[num]: print(Back.GREEN+'Правильно') rez = 1 isklucheniya.append(num) resultats.update({kana[num]:1}) else: print(Back.RED+'Неправильно') rez = -1 isklucheniya.append(num) resultats.update({kana[num]:-1}) break else: print(Fore.MAGENTA+ Back.BLACK + kana[num]) ja=input(Fore.RED) if ja == test_kana[num]: print(Back.GREEN+'Правильно') resultats.update({kana[num]:1}) isklucheniya.append(num) else: print(Back.RED+'Неправильно') resultats.update({kana[num]:-1}) isklucheniya.append(num) else: path = ROOT_DIR+ '\\sas.txt' print(Back.YELLOW) print(Fore.RED) f=open(path, 'w', encoding='utf-8') f.close() for i in resultats: if resultats[i] == 1: hor +=1 otvets = i +':'+str(resultats[i])+';' print(otvets) with open(path, 'a', encoding='utf-8') as f: f.write(otvets+'\n') procent = (100 * hor) / num_symbols print(Fore.CYAN+Back.BLACK+str(round(procent)) + '%') print('Правильных :'+str(hor) + ' Всего :'+ str(num_symbols)) with open(path, 'a', encoding='utf-8') as f: f.write(str(round(procent))+'%\n') f.write('Правильных :'+str(hor) + ' Всего :'+ str(num_symbols))