o99o99

Vocabulous 1.4

Jun 15th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.21 KB | None | 0 0
  1. #EDIT DEFAULT DICTIONARY HERE:
  2. filename = "words.txt"
  3.  
  4.  
  5.  
  6. ############################################################
  7. ## PLEASE NOTE: ##
  8. ## This program should be run in the Windows ##
  9. ## command window, not the Python IDLE. ##
  10. ############################################################
  11.  
  12.  
  13.  
  14. # CHANGELOG:
  15. #
  16. ############################################################
  17. #
  18. # 1.4
  19. #
  20. #-Added cls function to save typing
  21. #
  22. # 1.3
  23. #
  24. #-Added support for .vocab files
  25. #
  26. # 1.2
  27. #
  28. #-Added new final test
  29. # -Test on all words got wrong
  30. # -Added information text RE this
  31. #-Fixed 2 looping issues
  32. #-Minor "time.sleep", "print()" and "cls" edits
  33. #
  34. ############################################################
  35.  
  36.  
  37.  
  38.  
  39. ### BEGIN PROGRAM: ###
  40. def cls():
  41. os.system('cls' if os.name == 'nt' else 'clear')
  42.  
  43. import time
  44. import os
  45. print(" __ __ ___ __ ____ ____ __ __ _ ___ __ __ _____")
  46. print("| T | / \ / ] / || \ | | || | / \ | T T/ ___/")
  47. print("| | |Y Y / / / o || o )| | || | Y Y| | ( \_ ")
  48. print("| | || O | / / | || T| | || l | O || | |\__ \ ")
  49. print("| | |/ \_ | | || O || : || | | || : |/ \ |")
  50. print(" \ / l !\ || | || |l || |___ |l !l | |")
  51. print(" \_/ \___/ \____||__|__|l_____j \__,_jl_____j \___/ \__,_j \___j\n")
  52. print("1.3 OWAIN BATES\n")
  53. time.sleep(1)
  54. print(" Written by Owain Bates using Python 3.3.3")
  55. print(" With thanks to bedekelly and zahlman\n")
  56. print(" PLEASE MAXIMISE THIS WINDOW NOW\n")
  57. time.sleep(1)
  58. print()
  59. print()
  60. changefile = 0
  61. while changefile != 1 and changefile != 2:
  62. changefile = int(input("Type 1 select a dictionary, or type 2 to use the default dictionary words.txt: "))
  63. print()
  64. print()
  65. print()
  66. print()
  67. print()
  68. contsetup = 1
  69. while contsetup ==1:
  70. try:
  71. if changefile == 1:
  72. time.sleep(0.5)
  73. done =0
  74. if done == 0:
  75.  
  76. print(""" You can add your own dictionary now.
  77.  
  78. INSTRUCTIONS FOR CREATING DICTIONARIES:
  79.  
  80.  
  81. 1. Create a file in the same directory as this program.
  82. You can create it in another directory if you really want
  83. to, but you will have to enter the full file path below.
  84.  
  85. Make the file in notepad, and save it as either .txt or
  86. .vocab
  87.  
  88.  
  89. 2. Add your vocab. Make sure there is a new word each line.
  90. Do not leave empty lines, and do not have more than one
  91. word per line. You may have 1 OR 2 definitions per word.
  92. Any more than this will not work
  93.  
  94. It should be in the following format:
  95.  
  96. word:definition
  97. word:definition,definition2
  98. word:definition
  99.  
  100. Note that "word" can be anything at all, but the
  101. definitions must be strictly formatted. To answer
  102. a question correctly, you must type EXACTLY what
  103. you put for "definition" or (if applicable) "definition2".
  104.  
  105.  
  106. 3. Do not leave a space either side of the colon and (if
  107. applicable) the comma. You may leave a space where
  108. necessary if the definition consists of two words.
  109.  
  110.  
  111. 4. If you enter a word on two separate lines, the program
  112. will overwrite the first one with the second.
  113.  
  114.  
  115. 5. The program is case sensitive. Only capitalise definitions
  116. that should be capitalised.
  117.  
  118.  
  119. 6. Be careful when saving the file. Only ANSI and UTF-8 .txt
  120. formats are supported. Words with foreign characters will
  121. not appear at all using ANSI, and foreign characters will
  122. not render in other encoding formats.
  123.  
  124. 7. If you want to change the default dictionary, edit the
  125. first line of this code in the Python IDLE.
  126.  
  127. """)
  128. print()
  129. print()
  130. print()
  131. print()
  132. input("Press enter to continue")
  133.  
  134. print()
  135. textitems = os.listdir()
  136. newlist = []
  137. for names in textitems:
  138. if names.endswith(".txt") or names.endswith(".vocab"):
  139. newlist.append(names)
  140. time.sleep(0.5)
  141. print("Now choose a file.")
  142. print()
  143. time.sleep(0.5)
  144. print("The following text files are present in this directory: ", newlist)
  145. print()
  146. else:
  147. pass
  148. time.sleep(1)
  149. filename = input("Enter the file name you want: ")
  150. if not filename.endswith(".txt") and not filename.endswith(".vocab"):
  151. filename = filename + ".txt"
  152. pass
  153. else:
  154. pass
  155. done=1
  156. print()
  157. time.sleep(1)
  158. print()
  159. elif changefile == 2:
  160. time.sleep(1)
  161. print()
  162. contsetup =2
  163. else:
  164. time.sleep(0.5)
  165. print("Invalid choice. Try again.")
  166. print()
  167. contsetup =2
  168.  
  169. with open(filename) as file:
  170. if changefile == 1 or changefile == 2:
  171. print("The dictionary at", filename, "has been selected.")
  172. else:
  173. pass
  174. mdict={}
  175. for line in file:
  176. a, b = line.strip().split(':')
  177. if "," in b:
  178. b, c = b.split(",")
  179. adefs = (b,c)
  180. mdict[a] = adefs
  181. else:
  182. mdict[a] = b
  183. contsetup = 2
  184.  
  185. except ValueError:
  186. print()
  187. time.sleep(1)
  188. if contsetup !=2:
  189. input("MAJOR FORMATTING ERROR")
  190. input("""Whoops - that file doesn't seem to be formatted correctly. I'll repeat the
  191. instructions for you! Press enter to try again.""")
  192. cls()
  193. elif contsetup ==2:
  194. time.sleep(1)
  195. print()
  196. print("MINOR FORMATTING ERROR - NON FATAL")
  197. print("That file may have minor formatting issues.")
  198. print("Attempting to continue, however you may notice")
  199. print("a few problems with vocab. If this is the case,")
  200. print("please check over your custom dictionary for any")
  201. print("formatting errors.")
  202. time.sleep(1.5)
  203. else:
  204. pass
  205. print()
  206. print()
  207. print()
  208. print()
  209. print()
  210. time.sleep(0.5)
  211.  
  212. except FileNotFoundError:
  213. time.sleep(1)
  214. if contsetup !=2:
  215. input
  216. input("FILE ADDRESS ERROR")
  217. input("""Whoops - that file doesn't exist. I'll repeat the
  218. instructions for you! Press enter to try again.""")
  219. cls()
  220. else:
  221. pass
  222. print()
  223. print()
  224. print()
  225. print()
  226. print()
  227. time.sleep(0.50)
  228.  
  229.  
  230. time.sleep(0.5)
  231. print()
  232. print("The file has been successfully accessed!")
  233. dictlen = len(mdict)
  234. print()
  235. time.sleep(0.5)
  236. print("There are", dictlen, "words in the dictionary.")
  237. print()
  238. print()
  239. print()
  240. time.sleep(1)
  241. print("SETUP COMPLETE!")
  242. time.sleep(0.5)
  243. input("Press enter to continue")
  244. cls()
  245.  
  246. playagain = 1
  247. finalconf = 0
  248.  
  249. totalwrongdict = {}
  250.  
  251.  
  252. print("You can play as many games as you like. At the end,")
  253. print("you will be tested on every single word you got ")
  254. print("wrong, until you get them all correct!")
  255. time.sleep(1)
  256. print()
  257. print()
  258.  
  259. while playagain == 1 and finalconf!=1:
  260. time.sleep(1)
  261.  
  262. if playagain != 1:
  263. break
  264. else:
  265. pass
  266. print()
  267.  
  268. cont = 1
  269. wrongdict = {}
  270. score = 0
  271. qnum = 0
  272. wrongnum = 0
  273. lifelimit = 0
  274. gamemode = 0
  275. questionlimit = 0
  276. starttime = 0
  277. endtime = 0
  278.  
  279. while gamemode != 1 and gamemode != 2 and gamemode != 3:
  280. print("Please select your game mode.")
  281. time.sleep(0.5)
  282. print()
  283. print("In survival mode, the game ends after you lose all you lives.")
  284. print()
  285. print("In unlimited mode, the game goes on forever, until you type 'end'.")
  286. print()
  287. print("In test mode, you will be given a set number of questions to answer")
  288. print("against the clock.")
  289. print()
  290. gamemode = int(input("Press 1 to play survival, 2 to play unlimited or 3 to do a test: "))
  291. print()
  292. time.sleep(0.5)
  293. if gamemode == 1:
  294. while lifelimit < 1:
  295. print("Now select your number of lives.")
  296. lifelimit = int(input("This must be greater than 0: "))
  297. cls()
  298. print()
  299. if lifelimit < 1:
  300. print("Invalid number. Try again.")
  301. elif gamemode ==2:
  302. cls()
  303. print("To end your game on unlimited mode, type 'end'.")
  304. elif gamemode ==3:
  305. while questionlimit < 1:
  306. print("Select number of questions.")
  307. questionlimit = int(input("This must be greater than 0: "))
  308. cls()
  309. print()
  310. if questionlimit < 1:
  311. print("Invalid number. Try again.")
  312. else:
  313. print("Invalid game mode. Try again.")
  314. time.sleep(1)
  315. cls()
  316. print()
  317.  
  318. time.sleep(0.5)
  319. starttime = time.time()
  320. while cont ==1:
  321.  
  322. from random import choice
  323.  
  324. #Ask words
  325. print()
  326. q = choice(list(mdict.keys()))
  327. res = input('{0} is: '.format(q))
  328. qnum = qnum+1
  329. if res == "end" and gamemode == 2:
  330. print()
  331. time.sleep(0.3)
  332. cls()
  333. qnum = qnum-1
  334. break
  335. if res in mdict[q] and res != "":
  336. if gamemode != 3:
  337. time.sleep(0.3)
  338. print("Correct Answer!")
  339. else:
  340. pass
  341. score = score+1
  342. elif res not in mdict[q] or res == "":
  343. if gamemode != 3:
  344. time.sleep(0.7)
  345. print("Incorrect! The correct answer was:", mdict[q])
  346. else:
  347. pass
  348. if q not in wrongdict:
  349. wrongdict[q] = mdict[q]
  350. else:
  351. pass
  352. if q not in totalwrongdict:
  353. totalwrongdict[q] = mdict[q]
  354. else:
  355. pass
  356. wrongnum = wrongnum + 1
  357. #Loop/End
  358. if int(wrongnum) >= lifelimit and gamemode == 1:
  359. print()
  360. print()
  361. time.sleep(0.5)
  362. print("You have lost all", lifelimit, "lives!")
  363. time.sleep(1.5)
  364. cls()
  365. print()
  366. print("""
  367. ____ ____ ___ ___ ___ ___ __ __ ___ ____
  368. / T / T| T T / _] / \ | T | / _]| \
  369. Y __jY o || _ _ | / [_ Y Y| | | / [_ | D )
  370. | T || || \_/ |Y _] | O || | |Y _]| /
  371. | l_ || _ || | || [_ | |l : !| [_ | \
  372. | || | || | || T l ! \ / | T| . Y
  373. l___,_jl__j__jl___j___jl_____j \___/ \_/ l_____jl__j\_j
  374. """)
  375. print()
  376. time.sleep(0.8)
  377. input("Press enter to continue")
  378. cls()
  379.  
  380. print()
  381. cont = 2
  382. elif gamemode == 3 and qnum == questionlimit:
  383. endtime = time.time()
  384. timetaken = endtime-starttime
  385. timetaken = round(timetaken, 2)
  386. try:
  387. tpw = timetaken/score
  388. except ZeroDivisionError:
  389. twp = 0
  390. tpw = round(tpw, 2)
  391. print("The test is complete!")
  392. input("Press enter to continue")
  393. cls()
  394. cont = 2
  395. else:
  396. cont = 1
  397. try:
  398. percent = (round((100/qnum)*score))
  399. except ZeroDivisionError:
  400. percent = 0
  401.  
  402. time.sleep(1)
  403. print()
  404. print()
  405. print("CALCULATING SCORE!")
  406. time.sleep(1.5)
  407. if gamemode == 1:
  408. print()
  409. print("Your final score on survival mode was:", score, "/", qnum)
  410. if percent < 100:
  411. print("or", percent, "%")
  412. else:
  413. print("""
  414.  
  415.  
  416. d888 .d8888b. .d8888b. d88b d88P
  417. d8888 d88P Y88b d88P Y88b Y88P d88P
  418. 888 888 888 888 888 d88P
  419. 888 888 888 888 888 d88P
  420. 888 888 888 888 888 d88P
  421. 888 888 888 888 888 d88P
  422. 888 Y88b d88P Y88b d88P d88P d88b
  423. 8888888 "Y8888P" "Y8888P" d88P Y88P
  424.  
  425.  
  426. """)
  427. time.sleep(1)
  428. print()
  429. if wrongnum > 0:
  430. print("INCORRECT ANSWERS:")
  431. time.sleep(0.5)
  432. print()
  433. print("You got the following words wrong. They are listed with")
  434. print("their correct meainings: ")
  435. print()
  436. time.sleep(0.5)
  437. for key, value in wrongdict.items():
  438. print("{} : {}".format(key,value))
  439. print()
  440. print("Learn them!")
  441. elif wrongnum < 1:
  442. pass
  443. elif gamemode == 2:
  444. print()
  445. try:
  446. print("Your final score on unlimited mode was:", score, "/", qnum)
  447. if percent < 100:
  448. print("or", percent, "%")
  449. else:
  450. print("""
  451.  
  452.  
  453. d888 .d8888b. .d8888b. d88b d88P
  454. d8888 d88P Y88b d88P Y88b Y88P d88P
  455. 888 888 888 888 888 d88P
  456. 888 888 888 888 888 d88P
  457. 888 888 888 888 888 d88P
  458. 888 888 888 888 888 d88P
  459. 888 Y88b d88P Y88b d88P d88P d88b
  460. 8888888 "Y8888P" "Y8888P" d88P Y88P
  461.  
  462.  
  463. """)
  464. except ZeroDivisionError:
  465. print("You didn't answer any questions!")
  466. except NameError:
  467. print("You didn't answer anything!")
  468. time.sleep(0.5)
  469. time.sleep(0.5)
  470. print()
  471. if wrongnum > 0:
  472. print("INCORRECT ANSWERS:")
  473. time.sleep(0.5)
  474. print()
  475. print("You got the following words wrong. They are listed with")
  476. print("their correct meainings: ")
  477. print()
  478. time.sleep(0.5)
  479. for key, value in wrongdict.items():
  480. print("{} : {}".format(key,value))
  481. time.sleep(1.5)
  482. print()
  483. print("Learn them!")
  484. elif wrongnum < 1:
  485. pass
  486. elif gamemode == 3:
  487. print
  488. print("Your final score on the test was:", score, "/", qnum)
  489. if percent < 100:
  490. print("or", percent, "%")
  491. else:
  492. print("""
  493.  
  494.  
  495. d888 .d8888b. .d8888b. d88b d88P
  496. d8888 d88P Y88b d88P Y88b Y88P d88P
  497. 888 888 888 888 888 d88P
  498. 888 888 888 888 888 d88P
  499. 888 888 888 888 888 d88P
  500. 888 888 888 888 888 d88P
  501. 888 Y88b d88P Y88b d88P d88P d88b
  502. 8888888 "Y8888P" "Y8888P" d88P Y88P
  503.  
  504.  
  505. """)
  506. print("You took ", timetaken, "seconds!")
  507. if tpw != 0:
  508. print("Taking", tpw, "seconds per word!")
  509. else:
  510. pass
  511. time.sleep(0.5)
  512. time.sleep(0.5)
  513. print()
  514. if wrongnum > 0:
  515. print("INCORRECT ANSWERS:")
  516. time.sleep(0.5)
  517. print()
  518. print("You got the following words wrong. They are listed with")
  519. print("their correct meainings: ")
  520. print()
  521. time.sleep(0.5)
  522. for key, value in wrongdict.items():
  523. print("{} : {}".format(key,value))
  524. time.sleep(1.5)
  525. print()
  526. print("Learn them!")
  527. elif wrongnum < 1:
  528. pass
  529.  
  530. if percent == 100:
  531. comment = """
  532.  
  533.  
  534.  
  535. You got a perfect score! Congratulations! Try a new set of words, or play again to revise more!"""
  536. elif 100 > percent >= 90:
  537. comment = "Excellent score, well done! Play again to get an even better score!"
  538. elif 90 > percent >= 75:
  539. comment = "You got a decent score! Maybe you should try again to do better!"
  540. elif 75 > percent >= 60:
  541. comment = "You did okay, but you need to practise the words more!"
  542. elif 60 > percent >= 45:
  543. comment = "You didn't do too well. You need to learn these words better!"
  544. elif 45 > percent > 0:
  545. comment = "That was a pretty poor performance! Try again!"
  546. elif percent == 0:
  547. comment = "Pathetic! You scored nothing! You need to try again!"
  548.  
  549. print()
  550. time.sleep(1)
  551. print(comment)
  552. print()
  553. print()
  554. time.sleep(0.5)
  555. try:
  556. finalconf = int(input("Press enter to play again! Press 1 to exit "))
  557. except ValueError:
  558. finalconf = 0
  559. time.sleep(0.3)
  560. cls()
  561. if finalconf == 1:
  562. break
  563.  
  564. print()
  565. print()
  566. print()
  567. print("Here is a list of every incorrect word from this session.")
  568. print("Take note of them if you want to revise them.")
  569. time.sleep(0.3)
  570. print()
  571. for key, value in totalwrongdict.items():
  572. print("{} : {}".format(key,value))
  573. time.sleep(2)
  574. playagain = 2
  575.  
  576.  
  577. finconf = 0
  578. fintest = 1
  579. print()
  580. print("You will now take a final test on all of these words. They")
  581. print("will not be removed from the list until you answer them")
  582. print("correctly. This could take a long time!")
  583. print()
  584. input("Press enter to take the test: ")
  585. finaldict = {}
  586. finaldict = totalwrongdict.copy()
  587. cls()
  588. while fintest == 1:
  589. print()
  590. q = choice(list(totalwrongdict.keys()))
  591. res = input('{0} is: '.format(q))
  592. if res == "end":
  593. print()
  594. time.sleep(0.3)
  595. fintest = 0
  596. finconf = 1
  597. break
  598. elif res in totalwrongdict[q] and res != "":
  599. time.sleep(0.3)
  600. print("Correct Answer!")
  601. del totalwrongdict[q]
  602. elif res not in totalwrongdict[q] or res == "":
  603. time.sleep(0.7)
  604. print("Incorrect! The correct answer was:", mdict[q])
  605.  
  606. lengdi = len(totalwrongdict)
  607. if lengdi == 0:
  608. fintest = 0
  609. break
  610. else:
  611. pass
  612.  
  613.  
  614. time.sleep(1)
  615. print()
  616. print("Well done, you finally got them all right!")
  617. time.sleep(0.5)
  618. print("Here is that list once more:")
  619. time.sleep(1)
  620. print()
  621. for key, value in finaldict.items():
  622. print("{} : {}".format(key,value))
  623. time.sleep(2)
  624. print()
  625. input("Press enter to exit")
Advertisement
Add Comment
Please, Sign In to add comment