Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. for line in open(file, "r", encoding="UTF-8"):
  2. if ":" in line:
  3. (foreign, native) = line.rstrip("n").split(":")
  4. if "," in foreign:
  5. foreign_words += [foreign.split(",")]
  6. else:
  7. foreign_words += [foreign]
  8. if "," in native:
  9. native_words += [native.split(",")]
  10. else:
  11. native_words += [native]
  12. self.__foreign_words = foreign_words
  13. self.__native_words = native_words
  14. x = random.randint(0, (len(self.__foreign_words) - 1))
  15. self.__index.set(x)
  16.  
  17. if answer in correct_word:
  18. #deleting the words from the lists and congratulating
  19.  
  20. L = len(self.__foreign_words)
  21. x = random.randint(0, L - 1)
  22. #quits the program if the list length is 0
  23. if L > 0:
  24. if language == "F":
  25. correct_word = self.__native_words[x]
  26. elif language == "N":
  27. correct_word = self.__foreign_words[x]
  28.  
  29. if isinstance(correct_word, str):
  30. correct_word = correct_word
  31. else:
  32. correct_word = ", ".join(correct_word)
  33. self.__question.set(correct_word)
  34. # Above I only set the question to be in the form of "word, another word" or "word"
  35. # instead of ['word', 'another word'] or "word"
  36.  
  37. # this here I wish to improve
  38. if answer == correct_word:
  39. #here's also code that congratulates on correct answer (not included)
  40. del self.__foreign_words[x], self.__native_words[x]
  41. else:
  42. # telling you here how bad you are for not remembering the word (not included)
  43. y = self.__wrong_answers.get() + 1
  44. self.__wrong_answers.set(y)
  45. self.__foreign_words.append(self.__foreign_words[x])
  46. self.__native_words.append(self.__native_words[x])
  47.  
  48. #checks if the list is still not empty after deleting the previous ones
  49. if L - 1 > 0:
  50. x = random.randint(0, L - 1)
  51. self.__index.set(x)
  52. if language == "F":
  53. new_word = self.__foreign_words[x]
  54. if not isinstance(new_word, str):
  55. new_word = ", ".join(self.__foreign_words[x])
  56. self.__question.set(new_word)
  57.  
  58. elif language == "N":
  59. new_word = self.__native_words[x]
  60. if not isinstance(new_word, str):
  61. new_word = ", ".join(self.__native_words[x])
  62. self.__question.set(new_word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement