Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #EDIT DEFAULT DICTIONARY HERE:
- filename = "words.txt"
- import time
- import os
- print(" __ __ ___ __ ____ ____ __ __ _ ___ __ __ _____")
- print("| T | / \ / ] / || \ | | || | / \ | T T/ ___/")
- print("| | |Y Y / / / o || o )| | || | Y Y| | ( \_ ")
- print("| | || O | / / | || T| | || l | O || | |\__ \ ")
- print("| | |/ \_ | | || O || : || | | || : |/ \ |")
- print(" \ / l !\ || | || |l || |___ |l !l | |")
- print(" \_/ \___/ \____||__|__|l_____j \__,_jl_____j \___/ \__,_j \___j")
- print("1.0.0 o99o99\n")
- changefile = 0
- time.sleep(1)
- print(" Written by Owain Bates using Python 3.3.3")
- print(" With thanks to bedekelly and zahlman\n")
- print(" PLEASE MAXIMISE THIS WINDOW NOW\n")
- time.sleep(1)
- print()
- print()
- contsetup = 1
- while changefile != 1 and changefile != 2:
- changefile = int(input("Type 1 select a dictionary, or type 2 to use the default dictionary words.txt: "))
- print()
- print()
- print()
- print()
- print()
- while contsetup ==1:
- try:
- if changefile == 1:
- time.sleep(0.5)
- done =0
- if done == 0:
- print(""" You can add your own dictionary now.
- INSTRUCTIONS FOR CREATING DICTIONARIES:
- 1. Create a text file in the same directory as this program.
- You can create it in another directory if you really want
- to, but you will have to enter the full file path below.
- 2. Add your vocab. Make sure there is a new word each line.
- Do not leave empty lines, and do not have more than one
- word per line. You may have 1 OR 2 definitions per word.
- Any more than this will not work
- It should be in the following format:
- word:definition
- word:definition,definition2
- word:definition
- Note that "word" can be anything at all, but the
- definitions must be strictly formatted. To answer
- a question correctly, you must type EXACTLY what
- you put for "definition" or (if applicable) "definition2".
- 3. Do not leave a space either side of the colon and (if
- applicable) the comma. You may leave a space where
- necessary if the definition consists of two words.
- 4. If you enter a word on two separate lines, the program
- will overwrite the first one with the second.
- 5. The program is case sensitive. Only capitalise definitions
- that should be capitalised.
- 6. Be careful when saving the file. Only ANSI and UTF-8 .txt
- formats are supported. Words with foreign characters will
- not appear at all using ANSI, and foreign characters will
- not render in other encoding formats.
- 7. If you want to change the default dictionary, or specify
- a path to a default dictionary in a different directory,
- edit the first line of this code in the Python IDLE.
- """)
- print()
- print()
- print()
- print()
- input("Press enter to continue")
- print()
- textitems = os.listdir()
- newlist = []
- for names in textitems:
- if names.endswith(".txt"):
- newlist.append(names)
- time.sleep(0.5)
- print("Now choose a file.")
- print()
- time.sleep(0.5)
- print("The following text files are present in this directory: ", newlist)
- print()
- else:
- pass
- time.sleep(0.5)
- time.sleep(0.5)
- filename = input("Enter the file name or file path you want: ")
- if not filename.endswith(".txt"):
- filename = filename + ".txt"
- else:
- pass
- done=1
- print()
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- elif changefile == 2:
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- contsetup =2
- else:
- time.sleep(0.5)
- print("Invalid choice. Try again.")
- print()
- contsetup =2
- with open(filename) as file:
- print("The dictionary at", filename, "has been selected.")
- mdict={}
- for line in file:
- a, b = line.strip().split(':')
- if "," in b:
- b, c = b.split(",")
- adefs = (b,c)
- mdict[a] = adefs
- else:
- mdict[a] = b
- contsetup = 2
- except ValueError:
- print()
- time.sleep(1)
- input("""Whoops - that file doesn't seem to be formatted correctly. I'll repeat the
- instructions for you! Press enter to try again.""")
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- print()
- print()
- print()
- print()
- time.sleep(0.50)
- except FileNotFoundError:
- time.sleep(1)
- input("""Whoops - that file doesn't exist. I'll repeat the
- instructions for you! Press enter to try again.""")
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- print()
- print()
- print()
- print()
- time.sleep(0.50)
- time.sleep(0.5)
- print()
- print("The file has been successfully accessed!")
- dictlen = len(mdict)
- print()
- time.sleep(0.5)
- print("There are", dictlen, "words in the dictionary.")
- print()
- print()
- print()
- time.sleep(1)
- print("SETUP COMPLETE!")
- time.sleep(0.5)
- input("Press enter to continue")
- os.system('cls' if os.name == 'nt' else 'clear')
- playagain = 1
- while playagain == 1:
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- cont = 1
- wrongdict = {}
- score = 0
- qnum = 0
- wrongnum = 0
- lifelimit = 0
- gamemode = 0
- questionlimit = 0
- starttime = 0
- endtime = 0
- while gamemode != 1 and gamemode != 2 and gamemode != 3:
- print("Please select your game mode.")
- time.sleep(0.5)
- print()
- print("In survival mode, the game ends after you lose all you lives.")
- print("In unlimited mode, the game goes on forever, until you type 'end'.")
- print("In test mode, you will be given a set number of questions.")
- gamemode = int(input("Press 1 to play survival, 2 to play unlimited or 3 to do a test: "))
- print()
- time.sleep(0.5)
- if gamemode == 1:
- while lifelimit < 1:
- print("Now select your number of lives.")
- lifelimit = int(input("This must be greater than 0: "))
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- if lifelimit < 1:
- print("Invalid number. Try again.")
- elif gamemode ==2:
- print("To end your game on unlimited mode, type 'end'.")
- elif gamemode ==3:
- while questionlimit < 1:
- print("Select number of questions.")
- questionlimit = int(input("This must be greater than 0: "))
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- if questionlimit < 1:
- print("Invalid number. Try again.")
- else:
- print("Invalid game mode. Try again.")
- print()
- time.sleep(0.5)
- starttime = time.time()
- while cont ==1:
- from random import choice
- #Ask words
- print()
- q = choice(list(mdict.keys()))
- res = input('What is {0}? '.format(q))
- qnum = qnum+1
- if res == "end":
- print()
- time.sleep(0.3)
- os.system('cls' if os.name == 'nt' else 'clear')
- qnum = qnum-1
- break
- if res in mdict[q]:
- if gamemode != 3:
- time.sleep(0.3)
- else:
- pass
- print("Correct Answer!")
- score = score+1
- else:
- if gamemode != 3:
- time.sleep(0.8)
- else:
- pass
- print()
- print("Incorrect! The correct answer was:", mdict[q])
- wrongdict[q] = mdict[q]
- wrongnum = wrongnum + 1
- #Loop/End
- if int(wrongnum) >= lifelimit and gamemode == 1:
- print()
- print()
- time.sleep(0.5)
- print("You have lost all", lifelimit, "lives!")
- time.sleep(1.5)
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- print("""
- ____ ____ ___ ___ ___ ___ __ __ ___ ____
- / T / T| T T / _] / \ | T | / _]| \
- Y __jY o || _ _ | / [_ Y Y| | | / [_ | D )
- | T || || \_/ |Y _] | O || | |Y _]| /
- | l_ || _ || | || [_ | |l : !| [_ | \
- | || | || | || T l ! \ / | T| . Y
- l___,_jl__j__jl___j___jl_____j \___/ \_/ l_____jl__j\_j
- """)
- print()
- time.sleep(0.8)
- input("Press enter to continue")
- os.system('cls' if os.name == 'nt' else 'clear')
- print()
- cont = 2
- elif gamemode == 3 and qnum == questionlimit:
- endtime = time.time()
- timetaken = endtime-starttime
- timetaken = round(timetaken, 2)
- tpw = timetaken/score
- tpw = round(tpw, 2)
- print("The test is complete!")
- input("Press enter to continue")
- os.system('cls' if os.name == 'nt' else 'clear')
- cont = 2
- else:
- cont = 1
- try:
- percent = (round((100/qnum)*score))
- except ZeroDivisionError:
- percent = 0
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- print()
- print("CALCULATING SCORE!")
- time.sleep(0.5)
- time.sleep(0.5)
- time.sleep(0.5)
- time.sleep(0.5)
- if gamemode == 1:
- print()
- print("Your final score on survival mode was:", score, "/", qnum)
- if percent < 100:
- print("or", percent, "%")
- else:
- print("""
- d888 .d8888b. .d8888b. d88b d88P
- d8888 d88P Y88b d88P Y88b Y88P d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 Y88b d88P Y88b d88P d88P d88b
- 8888888 "Y8888P" "Y8888P" d88P Y88P
- """)
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- if wrongnum > 0:
- print("INCORRECT ANSWERS:")
- time.sleep(0.5)
- print()
- print("You got the following words wrong. They are listed with")
- print("their correct meainings: ")
- print()
- time.sleep(0.5)
- print(wrongdict)
- print()
- print("Learn them!")
- elif wrongnum < 1:
- pass
- elif gamemode == 2:
- print()
- try:
- print("Your final score on unlimited mode was:", score, "/", qnum)
- if percent < 100:
- print("or", percent, "%")
- else:
- print("""
- d888 .d8888b. .d8888b. d88b d88P
- d8888 d88P Y88b d88P Y88b Y88P d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 Y88b d88P Y88b d88P d88P d88b
- 8888888 "Y8888P" "Y8888P" d88P Y88P
- """)
- except ZeroDivisionError:
- print("You didn't answer any questions!")
- except NameError:
- print("You didn't answer anything!")
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- if wrongnum > 0:
- print("INCORRECT ANSWERS:")
- time.sleep(0.5)
- print()
- print("You got the following words wrong. They are listed with")
- print("their correct meainings: ")
- print()
- time.sleep(0.5)
- print(wrongdict)
- time.sleep(0.5)
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- print("Learn them!")
- elif wrongnum < 1:
- pass
- elif gamemode == 3:
- print()
- print("Your final score on the test was:", score, "/", qnum)
- if percent < 100:
- print("or", percent, "%")
- else:
- print("""
- d888 .d8888b. .d8888b. d88b d88P
- d8888 d88P Y88b d88P Y88b Y88P d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 888 888 888 888 d88P
- 888 Y88b d88P Y88b d88P d88P d88b
- 8888888 "Y8888P" "Y8888P" d88P Y88P
- """)
- print("You took ", timetaken, "seconds!")
- print("Taking", tpw, "seconds per word!")
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- if wrongnum > 0:
- print("INCORRECT ANSWERS:")
- time.sleep(0.5)
- print()
- print("You got the following words wrong. They are listed with")
- print("their correct meainings: ")
- print()
- time.sleep(0.5)
- print(wrongdict)
- time.sleep(0.5)
- time.sleep(0.5)
- time.sleep(0.5)
- print()
- print("Learn them!")
- elif wrongnum < 1:
- pass
- if percent == 100:
- comment = """
- You got a perfect score! Congratulations! Try a new set of words, or play again to revise more!"""
- elif 100 > percent >= 90:
- comment = "Excellent score, well done! Play again to get an even better score!"
- elif 90 > percent >= 75:
- comment = "You got a decent score! Maybe you should try again to do better!"
- elif 75 > percent >= 60:
- comment = "You did okay, but you need to practise the words more!"
- elif 60 > percent >= 45:
- comment = "You didn't do too well. You need to learn these words better!"
- elif 45 > percent > 0:
- comment = "That was a pretty poor performance! Try again!"
- elif percent == 0:
- comment = "Pathetic! You scored nothing! You need to try again!"
- print()
- time.sleep(1)
- print(comment)
- print()
- time.sleep(0.5)
- input("Press enter to play again! Close window to exit.")
- time.sleep(0.3)
- os.system('cls' if os.name == 'nt' else 'clear')
Advertisement
Add Comment
Please, Sign In to add comment