Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. #!/usr/bin/python3.2
  2. # -*-coding:Utf-8 -*
  3.  
  4. #Vocabulary/translation quiz
  5.  
  6. import os
  7. import random
  8.  
  9. keep_adding=input("Would you like to add a new word ? If yes, press "O" : ")
  10. while keep_adding=="O":
  11. entry=[]
  12. word=input("Enter a word : ")
  13. word=str(word)
  14. entry.append(word)
  15. translation=input("And its translation : ")
  16. translation=str(translation)
  17. entry.append(translation)
  18. entry=str(entry)
  19. f = open("data.txt","a")
  20. f.write(entry)
  21. f.close()
  22. keep_adding=input("To continue, press "O" : ")
  23.  
  24. f = open("data.txt","a") #in case the file doesn't exist, we create one
  25. f.close()
  26.  
  27. os.system('clear')
  28. print("* * * QUIZ STARTS ! * * *")
  29.  
  30. f = open("data.txt","r")
  31.  
  32. text = f.readlines()
  33. text = list(text)
  34. print("What is the translation for : ",text[0], "?")
  35. answer = input("Answer : ")
  36. if (answer == text[1]):
  37. print("Congratulations ! That's the good answer !")
  38. else:
  39. print("Wrong. The correct answer was : ",text[1])
  40.  
  41. * * * QUIZ STARTS ! * * *
  42. What is the translation for : ['alpha', 'bravo']['one', 'two']['x', 'y'] ?
  43. Answer : alpha
  44. Traceback (most recent call last):
  45. File "Python_progs/voc.py", line 43, in <module>
  46. if (answer == text[1]):
  47. IndexError: list index out of range
  48.  
  49. ['alpha', 'bravo']['one', 'two']['x', 'y']
  50.  
  51. f.write("line1")
  52. f.write("line2")
  53. f.write("line3")
  54.  
  55. line1line2line3
  56.  
  57. ["['alpha', 'bravo']['one', 'two']['x', 'y']"]
  58.  
  59. [a_string,]
  60.  
  61. if (answer == text[1]):
  62.  
  63. quiz, answer
  64. alpha, bravo
  65. one, two
  66. etc...
  67.  
  68. with open("myquizfile.txt", "w") as f:
  69. while keepGoing: #You'd have to add your own exit logic.
  70. question = input("Enter a question: ")
  71. answer = input("Enter an answer: ")
  72. f.write("{0},{1}n".format(question, answer)) #Notice the newline, n
  73.  
  74. with open("myquizfile.txt", "r") as f:
  75. question_answer_pairs = [line.split(",") for line in f]
  76.  
  77. #!/usr/bin/python3.2
  78. # -*-coding:Utf-8 -*
  79.  
  80. #Vocabulary/translation quiz
  81.  
  82. import os
  83. import random
  84.  
  85. keep_adding=input("Would you like to add a new word ? If yes, press "O" : ")
  86. with open("data.txt","a") as f:
  87. while keep_adding=="O":
  88. word=input("Enter a word : ")
  89. translation=input("And its translation : ")
  90. f.write("{0},{1},n".format(word,translation))
  91. keep_adding=input("To continue, press "O" : ")
  92.  
  93.  
  94. #in case the file doesn't exist, we create one :
  95. with open("data.txt","a") as f:
  96. pass
  97.  
  98. os.system('clear')
  99. print("* * * QUIZ STARTS ! * * *")
  100.  
  101. with open("data.txt","r") as f:
  102. question = [line.split(",") for line in f]
  103. i = 0
  104. score = 0
  105. while i<len(question):
  106. num = random.randint(0,len(question)-1)
  107. print("nQuestion number ",i+1,": nWhat is the translation for ", question[num][0], "?")
  108. answer = input("Answer : ")
  109. if (answer == str(question[num][1])):
  110. print("Congratulations ! That's the good answer !")
  111. score += 1
  112. else:
  113. print("Wrong. The correct answer was : ",question[num][1])
  114. i += 1
  115.  
  116. if len(question)==0:
  117. print("nThe file is empty. Please add new words to start the quiz !n")
  118. else:
  119. if i>1:
  120. qu_pl = "questions"
  121. else:
  122. qu_pl = "question"
  123. if score>1:
  124. sc_pl = "answers"
  125. else:
  126. sc_pl = "answer"
  127. print("n RESULTS :n ",i, qu_pl,", ",score,"correct ",sc_pl," n"
  128. ," --> Your score is : ",score*100/i,"% !n")
  129.  
  130. ### WORDLIST ###
  131. list = ['castigate','brave','prowess','tenacious','pre-emptive','orthodox','arcane','corpuscle','putrid','infidel','stratagem','affinity','abnegate','infraction']
  132. mean = ['to scold','courageous','skill','stubborn','early','traditional','mysterious','a living cell','rotting','unbeliever','scheme','attraction','to renounce','violation of law']
  133. list1 = list.copy()
  134.  
  135. mean1 = mean.copy()
  136. mean2 = mean.copy()
  137. mean3 = mean.copy()
  138. mean4 = mean.copy()
  139.  
  140. from random import randint
  141. import random
  142.  
  143. word_count = len(list) - 1
  144. options = []
  145.  
  146. options = random.sample(range(1, word_count), 4)
  147.  
  148. options1 = options.copy()
  149. options2 = options.copy()
  150. options3 = options.copy()
  151. options4 = options.copy()
  152. opt1 = options1.pop(0)
  153. opt2 = options2.pop(1)
  154. opt3 = options3.pop(2)
  155. opt4 = options4.pop(3)
  156.  
  157. x = randint(0,3)
  158. y = options.pop(x)
  159. #ignore [options]
  160. question = list.pop(y)
  161. answer = mean.pop(y)
  162.  
  163. print("What is the meaning of",question,"?")
  164. print("1)",mean1.pop(opt1))
  165. print("2)",mean2.pop(opt2))
  166. print("3)",mean3.pop(opt3))
  167. print("4)",mean4.pop(opt4))
  168.  
  169. while True:
  170. try:
  171. userans = int(input("nYour answer: "))
  172. except ValueError:
  173. print("Sorry, I didn't get that.")
  174. continue
  175. else:
  176. break
  177.  
  178. if userans - 1 is x:
  179. print("Your answer is correct!")
  180. else:
  181. if userans is 100:
  182. print("There are %s words in your personal dictionary" % word_count)
  183. else:
  184. if userans > 4:
  185. print("It's OK if you do not know the answer. Better luck next time:)nThe meaning of %s is %s!" % (question, answer))
  186. else:
  187. print("Your answer is wrong!nThe meaning of %s is %s!" % (question, answer))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement