Scrambled Word Game (Python) Topics: List, tuple In this lab, you will write a scrambled word game....

50.1K

Verified Solution

Question

Programming

Scrambled Word Game (Python)

Topics: List, tuple

In this lab, you will write a scrambled word game. The gamestarts by loading a file containing scrambled word-answer pairseparated. Sample of the file content is shown below. Once thepairs are loaded, it randomly pick a scrambled word and have theplayer guess it. The number of guesses is unlimited. When the userguess the correct answer, it asks the user if he/she wants anotherscrambled word.

bta:bat
gstoh:ghost
entsrom:monster

Download scrambled.py and halloween.txt. The file scrambled.pyalready has the print_banner and the load_words functions. Thefunction print_banner simply prints “scrambled” banner. Thefunction load_words load the list of scrambled words-answer pairsfrom the file and return a tuple of two lists. The first list isthe scrambled words and the second is the list of the answers. Yourjob is the complete the main function so that the game works asshown in the sample run.

Optional Challenge: The allowed numberof guess is equal to the length of the word. Print hints such asbased on the number of guess. If it’s the first guess, provides nohint. If it’s the second guess, provides the first letter of theanswer. If it’s the third guess, provides the first and secondletter of the correct answer. Also, make sure the same word is notselect twice. Once all words have been used, the game should telluser that all words have been used and terminate.

Sample run:

Scrambled word is: wbe
What is the word? bee
Wrong answer. Try again!
Scrambled word is: wbe
What is the word? web
You got it!
Another game? (Y/N):Y
Scrambled word is: meizob
What is the word? Zombie
You got it!
Another game? (Y/N):N
Bye!

Provided code:

def display_banner():
    print(\"\"\"

__                              _     _           _
/ _\ ___ _ __ __ _ _ __ ___ | |__ | | ___   __| |
\ \ / __|| '__|/ _` || '_ ` _ \ | '_ \ | | / _ \ / _` |
_\ \| (__ | | | (_| || | | | | || |_) || || __/| (_| |
\__/ \___||_|   \__,_||_| |_| |_||_.__/ |_| \___|\__,_|                                                       

\"\"\")

def load_words(filename):
    #load file containing scrambled word-answerpairs.
    #scrambled word and answer are sparated by :

    scrambled_list = []
    answer_list = []

    with open(filename, '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()
    (scrambled_list, answer_list) =load_words('halloween.txt')
    #your code to make the gamework.     

main()

Halloween.txt file.

bta:bat
gstoh:ghost
entsrom:monster
ihtcw:witch
meizob:zombie
enetskol:skeleton
rpamevi:vampire
wbe:web
isdepr:spider
umymm:mummy
rboom:broom
nhlwaeeol:Halloween
pkiumnp:pumpkin
kaoa jlern tcn:jack o lantern
tha:hat
claabck t:black cat
omno:moon
aurdclno:caluldron

Answer & Explanation Solved by verified expert
4.2 Ratings (726 Votes)
If you have any doubts please give mecommentdef displaybannerprint def loadwordsfilenameload file containing    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students