Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Scramble word game

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()

I am having a issue when it checks the users guess of the scrambled word that the program gives you and does not compare it to the right word.
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?
by

1 Answer

Bharatv4tg1
Thanks for pointing that out..but my program is not making it to that part because of the question I asked above.
and I can fix that part with by doing this. That was just a simple mistake on my part.
if another_game == 'Y' or another_game == 'y':
continue
if another_game == 'N' or another_game == 'n':
print('Bye')
done = True

Login / Signup to Answer the Question.