o99o99

Vocabulous Vocab Tester

May 10th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.66 KB | None | 0 0
  1. #EDIT DEFAULT DICTIONARY HERE:
  2. filename = "words.txt"
  3.  
  4.  
  5.  
  6. import time
  7. import os
  8.  
  9.  
  10. print(" __ __   ___      __   ____  ____   __ __  _       ___   __ __  _____")
  11. print("|  T  | /   \   /  ] /    ||    \ |  |  || |     /   \ |  T  T/ ___/")
  12. print("|  |  |Y     Y  /  / /  o  ||  o  )|  |  || |    Y     Y|  |  (   \_ ")
  13. print("|  |  ||  O  | /  /  |     ||     T|  |  || l    |  O  ||  |  |\__  \ ")
  14. print("|     |      |/  \_  |  |  ||  O  ||  :  || |    |     ||  :  |/  \ |")
  15. print(" \  / l     !\    ||  |  ||     |l     || |___ |l     !l     |    |")
  16. print("  \_/   \___/  \____||__|__|l_____j \__,_jl_____j \___/  \__,_j \___j")
  17.  
  18. print("1.0.0                                                          o99o99\n")
  19.  
  20.  
  21. changefile = 0
  22. time.sleep(1)
  23. print("    Written by Owain Bates using Python 3.3.3")
  24. print("    With thanks to bedekelly and zahlman\n")
  25. print("    PLEASE MAXIMISE THIS WINDOW NOW\n")
  26. time.sleep(1)
  27. print()
  28. print()
  29. contsetup = 1
  30. while changefile != 1 and changefile !=  2:
  31.     changefile = int(input("Type 1 select a dictionary, or type 2 to use the default dictionary words.txt: "))
  32.     print()
  33.     print()
  34.     print()
  35.     print()
  36.     print()
  37.     while contsetup ==1:
  38.         try:
  39.             if changefile == 1:
  40.                 time.sleep(0.5)
  41.                 done =0
  42.                 if done == 0:
  43.                    
  44.                     print("""   You can add your own dictionary now.
  45.  
  46.    INSTRUCTIONS FOR CREATING DICTIONARIES:
  47.    
  48.  
  49.    1. Create a text file in the same directory as this program.
  50.       You can create it in another directory if you really want
  51.       to, but you will have to enter the full file path below.
  52.  
  53.    
  54.    2. Add your vocab. Make sure there is a new word each line.
  55.       Do not leave empty lines, and do not have more than one
  56.       word per line. You may have 1 OR 2 definitions per word.
  57.       Any more than this will not work
  58.  
  59.       It should be in the following format:
  60.      
  61.           word:definition
  62.           word:definition,definition2
  63.           word:definition
  64.  
  65.        Note that "word" can be anything at all, but the
  66.        definitions must be strictly formatted. To answer
  67.        a question correctly, you must type EXACTLY what
  68.        you put for "definition" or (if applicable) "definition2".
  69.  
  70.  
  71.    3.  Do not leave a space either side of the colon and (if
  72.        applicable) the comma. You may leave a space where
  73.        necessary if the definition consists of two words.
  74.  
  75.        
  76.    4.  If you enter a word on two separate lines, the program
  77.        will overwrite the first one with the second.
  78.  
  79.          
  80.    5. The program is case sensitive. Only capitalise definitions
  81.       that should be capitalised.
  82.  
  83.  
  84.    6. Be careful when saving the file. Only ANSI and UTF-8 .txt
  85.       formats are supported. Words with foreign characters will
  86.       not appear at all using ANSI, and foreign characters will
  87.       not render in other encoding formats.
  88.  
  89.    7. If you want to change the default dictionary, or specify
  90.       a path to a default dictionary in a different directory,
  91.       edit the first line of this code in the Python IDLE.
  92.      
  93.                    """)
  94.                     print()
  95.                     print()
  96.                     print()
  97.                     print()
  98.                     input("Press enter to continue")
  99.  
  100.                     print()
  101.                     textitems = os.listdir()
  102.                     newlist = []
  103.                     for names in textitems:
  104.                         if names.endswith(".txt"):
  105.                             newlist.append(names)
  106.                     time.sleep(0.5)
  107.                     print("Now choose a file.")
  108.                     print()
  109.                     time.sleep(0.5)
  110.                     print("The following text files are present in this directory: ", newlist)
  111.                     print()
  112.                 else:
  113.                     pass
  114.                 time.sleep(0.5)
  115.                 time.sleep(0.5)
  116.                 filename = input("Enter the file name or file path you want: ")
  117.                 if not filename.endswith(".txt"):
  118.                     filename = filename + ".txt"
  119.                 else:
  120.                     pass
  121.                 done=1
  122.                 print()
  123.                 time.sleep(0.5)
  124.                
  125.                 time.sleep(0.5)
  126.                 print()
  127.             elif changefile == 2:
  128.                 time.sleep(0.5)
  129.                 time.sleep(0.5)
  130.                 print()
  131.                 contsetup =2
  132.             else:
  133.                 time.sleep(0.5)
  134.                 print("Invalid choice. Try again.")
  135.                 print()
  136.                 contsetup =2
  137.  
  138.             with open(filename) as file:
  139.                 print("The dictionary at", filename, "has been selected.")
  140.                 mdict={}
  141.                 for line in file:
  142.                     a, b = line.strip().split(':')
  143.                     if "," in b:
  144.                         b, c = b.split(",")
  145.                         adefs = (b,c)
  146.                         mdict[a] = adefs
  147.                     else:
  148.                         mdict[a] = b
  149.                     contsetup = 2
  150.  
  151.         except ValueError:
  152.             print()
  153.             time.sleep(1)
  154.             input("""Whoops - that file doesn't seem to be formatted correctly. I'll repeat the
  155. instructions for you! Press enter to try again.""")
  156.             os.system('cls' if os.name == 'nt' else 'clear')
  157.             print()
  158.             print()
  159.             print()
  160.             print()
  161.             print()
  162.             time.sleep(0.50)
  163.  
  164.         except FileNotFoundError:
  165.             time.sleep(1)
  166.             input("""Whoops - that file doesn't exist. I'll repeat the
  167. instructions for you! Press enter to try again.""")
  168.             os.system('cls' if os.name == 'nt' else 'clear')
  169.             print()
  170.             print()
  171.             print()
  172.             print()
  173.             print()
  174.             time.sleep(0.50)
  175.            
  176.  
  177. time.sleep(0.5)
  178. print()
  179. print("The file has been successfully accessed!")
  180. dictlen = len(mdict)
  181. print()
  182. time.sleep(0.5)
  183. print("There are", dictlen, "words in the dictionary.")
  184. print()
  185. print()
  186. print()
  187. time.sleep(1)
  188. print("SETUP COMPLETE!")
  189. time.sleep(0.5)
  190. input("Press enter to continue")
  191. os.system('cls' if os.name == 'nt' else 'clear')
  192.  
  193. playagain = 1
  194.  
  195. while playagain == 1:
  196.     time.sleep(0.5)
  197.     time.sleep(0.5)
  198.  
  199.     print()
  200.    
  201.     cont = 1
  202.     wrongdict = {}
  203.     score = 0
  204.     qnum = 0
  205.     wrongnum = 0
  206.     lifelimit = 0
  207.     gamemode = 0
  208.     questionlimit = 0
  209.     starttime = 0
  210.     endtime = 0
  211.              
  212.     while gamemode != 1 and gamemode != 2 and gamemode != 3:
  213.         print("Please select your game mode.")
  214.         time.sleep(0.5)
  215.         print()
  216.         print("In survival mode, the game ends after you lose all you lives.")
  217.         print("In unlimited mode, the game goes on forever, until you type 'end'.")
  218.         print("In test mode, you will be given a set number of questions.")
  219.         gamemode = int(input("Press 1 to play survival, 2 to play unlimited or 3 to do a test: "))
  220.         print()
  221.         time.sleep(0.5)
  222.         if gamemode == 1:
  223.             while lifelimit < 1:
  224.                 print("Now select your number of lives.")
  225.                 lifelimit = int(input("This must be greater than 0: "))
  226.                 os.system('cls' if os.name == 'nt' else 'clear')
  227.                 print()
  228.                 if lifelimit < 1:
  229.                     print("Invalid number. Try again.")
  230.         elif gamemode ==2:
  231.             print("To end your game on unlimited mode, type 'end'.")
  232.         elif gamemode ==3:
  233.             while questionlimit < 1:
  234.                 print("Select number of questions.")
  235.                 questionlimit = int(input("This must be greater than 0: "))
  236.                 os.system('cls' if os.name == 'nt' else 'clear')
  237.                 print()
  238.                 if questionlimit < 1:
  239.                     print("Invalid number. Try again.")
  240.         else:
  241.             print("Invalid game mode. Try again.")
  242.             print()
  243.  
  244.         time.sleep(0.5)
  245.         starttime = time.time()
  246.         while cont ==1:
  247.            
  248.             from random import choice
  249.            
  250. #Ask words
  251.             print()
  252.             q = choice(list(mdict.keys()))
  253.             res = input('What is {0}? '.format(q))
  254.             qnum = qnum+1
  255.             if res == "end":
  256.                 print()
  257.                 time.sleep(0.3)
  258.                 os.system('cls' if os.name == 'nt' else 'clear')
  259.                 qnum = qnum-1
  260.                 break
  261.             if res in mdict[q]:
  262.                 if gamemode != 3:
  263.                     time.sleep(0.3)
  264.                 else:
  265.                     pass
  266.                 print("Correct Answer!")
  267.                 score = score+1
  268.             else:
  269.                 if gamemode != 3:
  270.                     time.sleep(0.8)
  271.                 else:
  272.                     pass
  273.                 print()
  274.                 print("Incorrect! The correct answer was:", mdict[q])
  275.                 wrongdict[q] = mdict[q]
  276.                 wrongnum = wrongnum + 1
  277. #Loop/End        
  278.             if int(wrongnum) >= lifelimit and gamemode == 1:
  279.                 print()
  280.                 print()
  281.                 time.sleep(0.5)
  282.                 print("You have lost all", lifelimit, "lives!")
  283.                 time.sleep(1.5)
  284.                 os.system('cls' if os.name == 'nt' else 'clear')
  285.                 print()
  286.                 print("""
  287.  ____   ____  ___ ___    ___       ___   __ __    ___  ____  
  288. /    T /    T|   T   T  /  _]     /   \ |  T  |  /  _]|    \
  289. Y   __jY  o  || _   _ | /  [_     Y     Y|  |  | /  [_ |  D  )
  290. |  T  ||     ||  \_/  |Y    _]    |  O  ||  |  |Y    _]|    /
  291. |  l_ ||  _  ||   |   ||   [_     |     |l  :  !|   [_ |    \
  292. |     ||  |  ||   |   ||     T    l     ! \  / |     T|  .  Y
  293. l___,_jl__j__jl___j___jl_____j     \___/   \_/  l_____jl__j\_j
  294.                                                              """)
  295.                 print()
  296.                 time.sleep(0.8)
  297.                 input("Press enter to continue")
  298.                 os.system('cls' if os.name == 'nt' else 'clear')
  299.                
  300.                 print()
  301.                 cont = 2
  302.             elif gamemode == 3 and qnum == questionlimit:
  303.                 endtime = time.time()
  304.                 timetaken = endtime-starttime
  305.                 timetaken = round(timetaken, 2)
  306.                 tpw = timetaken/score
  307.                 tpw = round(tpw, 2)
  308.                 print("The test is complete!")
  309.                 input("Press enter to continue")
  310.                 os.system('cls' if os.name == 'nt' else 'clear')
  311.                 cont = 2
  312.             else:
  313.                 cont = 1
  314.         try:      
  315.             percent = (round((100/qnum)*score))
  316.         except ZeroDivisionError:
  317.             percent = 0
  318.        
  319.         time.sleep(0.5)
  320.         time.sleep(0.5)
  321.         print()
  322.         print()
  323.         print("CALCULATING SCORE!")
  324.         time.sleep(0.5)
  325.         time.sleep(0.5)
  326.         time.sleep(0.5)
  327.         time.sleep(0.5)
  328.     if gamemode == 1:
  329.         print()
  330.         print("Your final score on survival mode was:", score, "/", qnum)
  331.         if percent < 100:
  332.             print("or", percent, "%")
  333.         else:
  334.             print("""
  335.  
  336.  
  337. d888    .d8888b.   .d8888b.  d88b   d88P
  338. d8888   d88P  Y88b d88P  Y88b Y88P  d88P
  339.  888   888    888 888    888      d88P  
  340.  888   888    888 888    888     d88P  
  341.  888   888    888 888    888    d88P    
  342.  888   888    888 888    888   d88P    
  343.  888   Y88b  d88P Y88b  d88P  d88P  d88b
  344. 8888888  "Y8888P"   "Y8888P"  d88P   Y88P
  345.  
  346.  
  347. """)
  348.         time.sleep(0.5)
  349.         time.sleep(0.5)
  350.         print()
  351.         if wrongnum > 0:
  352.             print("INCORRECT ANSWERS:")
  353.             time.sleep(0.5)
  354.             print()
  355.             print("You got the following words wrong. They are listed with")
  356.             print("their correct meainings: ")
  357.             print()
  358.             time.sleep(0.5)
  359.             print(wrongdict)
  360.             print()
  361.             print("Learn them!")
  362.         elif wrongnum < 1:
  363.             pass
  364.     elif gamemode == 2:
  365.         print()
  366.         try:
  367.             print("Your final score on unlimited mode was:", score, "/", qnum)
  368.             if percent < 100:
  369.                 print("or", percent, "%")
  370.             else:
  371.                 print("""
  372.  
  373.  
  374. d888    .d8888b.   .d8888b.  d88b   d88P
  375. d8888   d88P  Y88b d88P  Y88b Y88P  d88P
  376.  888   888    888 888    888      d88P  
  377.  888   888    888 888    888     d88P  
  378.  888   888    888 888    888    d88P    
  379.  888   888    888 888    888   d88P    
  380.  888   Y88b  d88P Y88b  d88P  d88P  d88b
  381. 8888888  "Y8888P"   "Y8888P"  d88P   Y88P
  382.  
  383.  
  384. """)
  385.         except ZeroDivisionError:
  386.             print("You didn't answer any questions!")
  387.         except NameError:
  388.             print("You didn't answer anything!")
  389.         time.sleep(0.5)
  390.         time.sleep(0.5)
  391.         print()
  392.         if wrongnum > 0:
  393.             print("INCORRECT ANSWERS:")
  394.             time.sleep(0.5)
  395.             print()
  396.             print("You got the following words wrong. They are listed with")
  397.             print("their correct meainings: ")
  398.             print()
  399.             time.sleep(0.5)
  400.             print(wrongdict)
  401.             time.sleep(0.5)
  402.             time.sleep(0.5)
  403.             time.sleep(0.5)
  404.             print()
  405.             print("Learn them!")
  406.         elif wrongnum < 1:
  407.             pass
  408.     elif gamemode == 3:
  409.         print()
  410.         print("Your final score on the test was:", score, "/", qnum)
  411.         if percent < 100:
  412.             print("or", percent, "%")
  413.         else:
  414.             print("""
  415.  
  416.  
  417. d888    .d8888b.   .d8888b.  d88b   d88P
  418. d8888   d88P  Y88b d88P  Y88b Y88P  d88P
  419.  888   888    888 888    888      d88P  
  420.  888   888    888 888    888     d88P  
  421.  888   888    888 888    888    d88P    
  422.  888   888    888 888    888   d88P    
  423.  888   Y88b  d88P Y88b  d88P  d88P  d88b
  424. 8888888  "Y8888P"   "Y8888P"  d88P   Y88P
  425.  
  426.  
  427. """)
  428.         print("You took ", timetaken, "seconds!")
  429.         print("Taking", tpw, "seconds per word!")
  430.         time.sleep(0.5)
  431.         time.sleep(0.5)
  432.         print()
  433.         if wrongnum > 0:
  434.             print("INCORRECT ANSWERS:")
  435.             time.sleep(0.5)
  436.             print()
  437.             print("You got the following words wrong. They are listed with")
  438.             print("their correct meainings: ")
  439.             print()
  440.             time.sleep(0.5)
  441.             print(wrongdict)
  442.             time.sleep(0.5)
  443.             time.sleep(0.5)
  444.             time.sleep(0.5)
  445.             print()
  446.             print("Learn them!")
  447.         elif wrongnum < 1:
  448.             pass
  449.  
  450.     if percent == 100:
  451.         comment = """
  452.  
  453.  
  454.  
  455. You got a perfect score! Congratulations! Try a new set of words, or play again to revise more!"""
  456.     elif 100 > percent >= 90:
  457.         comment = "Excellent score, well done! Play again to get an even better score!"
  458.     elif 90 > percent >= 75:
  459.         comment = "You got a decent score! Maybe you should try again to do better!"
  460.     elif 75 > percent >= 60:
  461.         comment = "You did okay, but you need to practise the words more!"
  462.     elif 60 > percent >= 45:
  463.         comment = "You didn't do too well. You need to learn these words better!"
  464.     elif 45 > percent > 0:
  465.         comment = "That was a pretty poor performance! Try again!"
  466.     elif percent == 0:
  467.         comment = "Pathetic! You scored nothing! You need to try again!"
  468.        
  469.     print()
  470.     time.sleep(1)
  471.     print(comment)
  472.     print()
  473.     time.sleep(0.5)
  474.     input("Press enter to play again! Close window to exit.")
  475.     time.sleep(0.3)
  476.     os.system('cls' if os.name == 'nt' else 'clear')
Advertisement
Add Comment
Please, Sign In to add comment