Feb-04-2018, 09:08 PM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
def display_banner(): print ( """ __ _ _ _ / _\ ___ _ __ __ _ _ __ ___ | |__ | | ___ __| | \ \ / __|| '__|/ _` || '_ ` _ \ | '_ \ | | / _ \ / _` | _\ \| (__ | | | (_| || | | | | || |_) || || __/| (_| | \__/ \___||_| \__,_||_| |_| |_||_.__/ |_| \___| \__,_| """ ) def load_words(filename): #load file containing scrambled word and answer. #scrambled word and answer are separated by : scrambled_list = [] answer_list = [] with open ( 'halloween.txt' , 'r' ) as f: for line in f: (s,a) = line.strip().split( ":" ) scrambled_list + = [s] answer_list + = [a] return (scrambled_list, answer_list) def main(): display_banner() import random file = open ( 'halloween.txt' , 'w' ) file .write( 'bta:bat\n' ) file .write( 'gstoh:ghost\n' ) file .write( 'enstrom:monster\n' ) file .write( 'ihtcw:witch\n' ) file .write( 'meizob:zombie\n' ) file .write( 'enetskol:skeleton\n' ) file .write( 'rpamevi:vampire\n' ) file .write( 'wbe:web\n' ) file .write( 'isdepr:spider\n' ) file .write( 'umymm:mummy\n' ) file .write( 'rboom:broom\n' ) file .write( 'nhlwaeeol:halloween\n' ) file .write( 'pkiumnp:pumpkin\n' ) file .write( 'kaoa jlern tcn:jack o lantern\n' ) file .write( 'tha:hat\n' ) file .write( 'claabck t:black cat\n' ) file .write( 'omno:moon\n' ) file .write( 'aurdclno:cauldron\n' ) file .close() done = False while not done: (scrambled_list, answer_list) = load_words( 'halloween.txt' ) file = open ( 'halloween.txt' , 'r' ) scrambled = random.choice(scrambled_list) #pick one word randomly from list created from file user_guess = answer_list print ( 'scrambled word is:' , scrambled) guess = input ( 'What is the word?' ) if guess ! = user_guess: print ( 'Wrong answer. Try again!' ) elif guess = = user_guess: print ( 'You got it!' ) another_game = input ( 'Another game? (Y/N):' ) if another_game = = 'Y' or 'y' : continue if another_game = = 'N' or 'n' : print ( 'Bye' ) done = True #-------------------------- # Randomly pick a scrambled word from the list. # Asks the user to guess it. # Ask again if the guess is wrong. Rpeat until the guess is right. # If guess is right, ask if user wants another game. #-------------------------- main() |
So it just keeps looping like this.
scrambled word is: rboom
What is the word?broom
Wrong answer. Try again!
scrambled word is: pkiumnp
What is the word?pumpkin
Wrong answer. Try again!
scrambled word is: claabck t
What is the word?