Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scramble word game
#1
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?
Reply


Messages In This Thread
Scramble word game - by Zatoichi - Feb-04-2018, 09:08 PM
RE: Scramble word game - by buran - Feb-04-2018, 09:15 PM
RE: Scramble word game - by Zatoichi - Feb-04-2018, 09:22 PM
RE: Scramble word game - by buran - Feb-04-2018, 09:42 PM
RE: Scramble word game - by Zatoichi - Feb-04-2018, 09:56 PM
RE: Scramble word game - by piday - Feb-05-2018, 02:04 AM
RE: Scramble word game - by Zatoichi - Feb-05-2018, 02:46 AM
RE: Scramble word game - by jefsummers - Sep-13-2021, 08:17 PM
RE: Scramble word game - by jefsummers - Sep-19-2021, 12:30 PM
RE: Scramble word game - by jefsummers - Sep-20-2021, 03:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help creating a word game wthiierry 4 2,411 Nov-01-2022, 12:29 PM
Last Post: perfringo
  Word based Game of 21 DatNerdKid 2 76,739 Aug-24-2018, 03:25 PM
Last Post: DuaneJack
  Scramble and Interleave in Python dsaks 5 5,096 Jun-13-2018, 10:10 PM
Last Post: dsaks
  scrabble word game atux_null 4 8,744 Nov-10-2017, 10:00 AM
Last Post: atux_null

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020