Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for line in open(file, "r", encoding="UTF-8"):
- if ":" in line:
- (foreign, native) = line.rstrip("n").split(":")
- if "," in foreign:
- foreign_words += [foreign.split(",")]
- else:
- foreign_words += [foreign]
- if "," in native:
- native_words += [native.split(",")]
- else:
- native_words += [native]
- self.__foreign_words = foreign_words
- self.__native_words = native_words
- x = random.randint(0, (len(self.__foreign_words) - 1))
- self.__index.set(x)
- if answer in correct_word:
- #deleting the words from the lists and congratulating
- L = len(self.__foreign_words)
- x = random.randint(0, L - 1)
- #quits the program if the list length is 0
- if L > 0:
- if language == "F":
- correct_word = self.__native_words[x]
- elif language == "N":
- correct_word = self.__foreign_words[x]
- if isinstance(correct_word, str):
- correct_word = correct_word
- else:
- correct_word = ", ".join(correct_word)
- self.__question.set(correct_word)
- # Above I only set the question to be in the form of "word, another word" or "word"
- # instead of ['word', 'another word'] or "word"
- # this here I wish to improve
- if answer == correct_word:
- #here's also code that congratulates on correct answer (not included)
- del self.__foreign_words[x], self.__native_words[x]
- else:
- # telling you here how bad you are for not remembering the word (not included)
- y = self.__wrong_answers.get() + 1
- self.__wrong_answers.set(y)
- self.__foreign_words.append(self.__foreign_words[x])
- self.__native_words.append(self.__native_words[x])
- #checks if the list is still not empty after deleting the previous ones
- if L - 1 > 0:
- x = random.randint(0, L - 1)
- self.__index.set(x)
- if language == "F":
- new_word = self.__foreign_words[x]
- if not isinstance(new_word, str):
- new_word = ", ".join(self.__foreign_words[x])
- self.__question.set(new_word)
- elif language == "N":
- new_word = self.__native_words[x]
- if not isinstance(new_word, str):
- new_word = ", ".join(self.__native_words[x])
- self.__question.set(new_word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement