Question

***How do I insert the Halloween text into this and write the program**** Topics: List, tuple...

***How do I insert the Halloween text into this and write the program****

Topics: List, tuple

In this lab, you will write a scrambled word game.  The game starts by loading a file containing scrambled word-answer pair separated.  Sample of the file content is shown below.  Once the pairs are loaded, it randomly picks a scrambled word and has the player guess it.  The number of guesses is unlimited.  When the user guesses the correct answer, it asks the user if he/she wants another scrambled word.  

bta:bat
gstoh:ghost
entsrom:monster

Download scrambled.py and halloween.txt from blackboard under labs/lab5.  The file scrambled.py already has the print_banner and the load_words functions.  The function print_banner simply prints “scrambled” banner.  The function load_words load the list of scrambled words-answer pairs from the file and return a tuple of two lists.  The first list is the scrambled words and the second is the list of the answers.  Your job is the complete the main function so that the game works as shown in the sample run.

Optional Challenge:  The allowed number of guess is equal to the length of the word.  Print hints such as based on the number of guess.  If it’s the first guess, provides no hint.  If it’s the second guess, provides the first letter of the answer.  If it’s the third guess, provides the first and second letter of the correct answer.  Also, make sure the same word is not select twice.  Once all words have been used, the game should tell user 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-answer pairs.
    #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 game work.      

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please read the comments to understand the code. It's fairly simple. You'll get it.

THE CODE IS

from random import randint

def display_banner():
#print the banner SCRAMBLED
print("""
__ _ _ _
/ _\ ___ _ __ __ _ _ __ ___ | |__ | | ___ __| |
\ \ / __|| '__|/ _` || '_ ` _ \ | '_ \ | | / _ \ / _` |
_\ \| (__ | | | (_| || | | | | || |_) || || __/| (_| |
\__/ \___||_| \__,_||_| |_| |_||_.__/ |_| \___| \__,_|   

""")

def load_words(filename):
#load file containing scrambled word-answer pairs.
#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('D:\\Chegg\\Halloween.txt') #This is link to File called Halloween.txt
  
#your code to make the game work.
#The code has been made taking into consideration the OPTIONAL CHALLENGE as well
numbersAlreadyGenerated=[] #so that words are not repeated
while 1:
attempts=0 #Number of attemots given to user
value = randint(0, scrambled_list.__len__()-1) #randomly generating number
  
while value in numbersAlreadyGenerated: #if words has already been asked
value = randint(0, scrambled_list.__len__()-1) #generate new word
  
won=0; #check if the user has won a turn or he has lost the turn
  
while attempts<scrambled_list[value].__len__(): #Restricitng number of attempts to number
#of letters in word
print('Scrambled word is: ',scrambled_list[value],end='')
if attempts>0: #if it's not the first attempt show hint accordingly
v=""
temp=0
while temp<attempts: #hint has start letter to one less than attempt
v=v+(answer_list[value])[temp] #Generate hint word
temp=temp+1
  
print('\nHint: ',v, end='')
  
userGuess=input('What is the word? ') #ask user's guess
if userGuess==answer_list[value]: #if he guessed right
print('You got it!')
won=1
break
else:
print('Wrong answer. Try again!\n')
attempts=attempts+1   
  
if not won: #if his attempts are over and he has not won
print('Your Attempts are over.\nThe right word: ',answer_list[value])
  
numbersAlreadyGenerated.append(value) #the word number that has been shown
if numbersAlreadyGenerated.__len__()==scrambled_list.__len__():
print("All the words have been used") #if all words have been used
print("Bye")
break
  
ans=input('Another Game? (Y/N): ') #Does user wants another game?
if(ans=='N' or ans=='n'):
print('Bye!')
break

main()

OUTPUT:

In this two output have been demonstrated in accordance to the OPTIONAL CHALLENGE. The functionalities include:-

1. Limited Number Of Attempts- Equal to the number of letters in word.

2. Hint Generating.

3. Normal Game Scenario.

4. Exit when all words end or User says NO to play more.

Hope You understood. Please HIT Like and Rate. Good luck.

Add a comment
Know the answer?
Add Answer to:
***How do I insert the Halloween text into this and write the program**** Topics: List, tuple...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • Learn how to use the advanced data structures (such as: list, tuple, string, dictionary, and set)...

    Learn how to use the advanced data structures (such as: list, tuple, string, dictionary, and set) ·         Learn and practice how to use functions. ·         Learn and practice how to use file I/Os. ·         Appreciate the importance of data validations. ·         Provide appropriate documentation and good programming style. Python Programming Description of the problem: Write a “censor” program that first reads a file with “bad words” such as “sex”, “drug”, “rape”, “kill”, and so on, places them in a set, and then reads an...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • ​ TEXT FILE IS ALREADY GIVEN, JUST NEED TO READ IN THE PROGRAM. Learning objectives: The...

    ​ TEXT FILE IS ALREADY GIVEN, JUST NEED TO READ IN THE PROGRAM. Learning objectives: The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming. This project HANG MAN will focus on file I/O and string manipulation in the implementation of the game Hangman. Program Description: In this project, you will write a C++ program that simulates playing the game Hangman. This version of the game will...

  • Help c++ Description: This program is part 1 of a larger program. Eventually, it will be...

    Help c++ Description: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This will help you prepare for next week Print the final messages of...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • This is for C programming: You will be given files in the following format: n word1...

    This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT