Menu

[Solved]Python Programming Codes Copy Problem Set 2 Hangmanpy Name Sung Min Lim Collaborators Time Q37076924

THIS IS PYTHON PROGRAMMING

CODES TO COPY:

# Problem Set 2, hangman.py
# Name: Sung Min Lim
# Collaborators:
# Time spent:

# Hangman Game
# ———————————–
# Helper code
# You don’t need to understand this helper code,
# but you will have to know how to use the functions
# (so be sure to read the docstrings!)
import random
import string

WORDLIST_FILENAME = “words.txt”

def load_words():
“””
Returns a list of valid words. Words are strings of lowercaseletters.
  
Depending on the size of the word list, this function may
take a while to finish.
“””
print(“Loading word list from file…”)
# inFile: file
inFile = open(WORDLIST_FILENAME, ‘r’)
# line: string
line = inFile.readline()
# wordlist: list of strings
wordlist = line.split()
print(” “, len(wordlist), “words loaded.”)
return wordlist

def choose_word(wordlist):
“””
wordlist (list): list of words (strings)
  
Returns a word from wordlist at random
“””
return random.choice(wordlist)

# end of helper code

# ———————————–

# Load the list of words into the variable wordlist
# so that it can be accessed from anywhere in the program
wordlist = load_words()

def is_word_guessed(secret_word, letters_guessed):
”’
secret_word: string, the word the user is guessing; assumes allletters are
lowercase
letters_guessed: list (of letters), which letters have been guessedso far;
assumes that all letters are lowercase
returns: boolean, True if all the letters of secret_word are inletters_guessed;
False otherwise
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
##for (int i = 0; i < secret_letters.size(); i++)
   ##{
   ##   secret_letters[i] ==letters_guessed
   ##}

   while i< len(letters_guessed):  
       string = letters_guessed[i]  
       if string in secret_word:  
           print(“Yay, yougot this!”)
       else
           print(“Trysomething else.”)
       i+= 1
      
       for i in range(times):  
           print(word,”!!!”)   
  
   pass
  
  

def get_guessed_word(secret_word, letters_guessed):
”’
secret_word: string, the word the user is guessing
letters_guessed: list (of letters), which letters have been guessedso far
returns: string, comprised of letters, underscores (_), and spacesthat represents
which letters in secret_word have been guessed so far.
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass

def get_available_letters(letters_guessed):
”’
letters_guessed: list (of letters), which letters have been guessedso far
returns: string (of letters), comprised of letters that representswhich letters have not
yet been guessed.
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass
  
  

def hangman(secret_word):
”’
secret_word: string, the secret word to guess.
  
Starts up an interactive game of Hangman.
  
* At the start of the game, let the user know how many
letters the secret_word contains and how many guesses s/he startswith.
  
* The user should start with 6 guesses

* Before each round, you should display to the user how manyguesses
s/he has left and the letters that the user has not yetguessed.
  
* Ask the user to supply one guess per round. Remember tomake
sure that the user puts in a letter!
  
* The user should receive feedback immediately after eachguess
about whether their guess appears in the computer’s word.

* After each guess, you should display to the user the
partially guessed word so far.
  
Follows the other limitations detailed in the problemwrite-up.
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass

# When you’ve completed your hangman function, scroll down tothe bottom
# of the file and uncomment the first two lines to test
#(hint: you might want to pick your own
# secret_word while you’re doing your own testing)

# ———————————–

def match_with_gaps(my_word, other_word):
”’
my_word: string with _ characters, current guess of secretword
other_word: string, regular English word
returns: boolean, True if all the actual letters of my_word matchthe
corresponding letters of other_word, or the letter is the specialsymbol
_ , and my_word and other_word are of the same length;
False otherwise:
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass

def show_possible_matches(my_word):
”’
my_word: string with _ characters, current guess of secretword
returns: nothing, but should print out every word in wordlist thatmatches my_word
Keep in mind that in hangman when a letter is guessed, all thepositions
at which that letter occurs in the secret word are revealed.
Therefore, the hidden letter(_ ) cannot be one of the letters inthe word
that has already been revealed.

”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass

def hangman_with_hints(secret_word):
”’
secret_word: string, the secret word to guess.
  
Starts up an interactive game of Hangman.
  
* At the start of the game, let the user know how many
letters the secret_word contains and how many guesses s/he startswith.
  
* The user should start with 6 guesses
  
* Before each round, you should display to the user how manyguesses
s/he has left and the letters that the user has not yetguessed.
  
* Ask the user to supply one guess per round. Make sure to checkthat the user guesses a letter
  
* The user should receive feedback immediately after eachguess
about whether their guess appears in the computer’s word.

* After each guess, you should display to the user the
partially guessed word so far.
  
* If the guess is the symbol *, print out all words in wordlistthat
matches the current guessed word.
  
Follows the other limitations detailed in the problemwrite-up.
”’
# FILL IN YOUR CODE HERE AND DELETE “pass”
pass

# When you’ve completed your hangman_with_hint function, commentthe two similar
# lines above that were used to run the hangman function, and thenuncomment
# these two lines and run this file to test!
# Hint: You might want to pick your own secret_word while you’retesting.

if __name__ == “__main__”:
# pass

# To test part 2, comment out the pass line above and
# uncomment the following two lines.
  
secret_word = choose_word(wordlist)
hangman(secret_word)

###############
  
# To test part 3 re-comment out the above lines and
# uncomment the following two lines.
  
#secret_word = choose_word(wordlist)
#hangman_with_hints(secret_word)

IMAGES:

# Problem Set 2, hangman . RY # Name: Sung Min ham # Collaborators: # Time spent: # Hangman Game # Helper code # You don t ndef is word quessed (secret word, letters quessed) secret_word: string, the word the user is guessing: assumes al1 letters arBefore each round, you should display to the user how many guesses s/he has left and the letters that the user has not yet gu# FILL IN YOUR CODE HERE AND DELETE pass pass def hangman_with hints (secret_word): secret_word: string, the secret word toif _name-main: # pass # To test part 2, comment out the pass line above and # uncomment the following two lines. secret word

# Problem Set 2, hangman . RY # Name: Sung Min ham # Collaborators: # Time spent: # Hangman Game # Helper code # You don ‘t need to understand this helper code, # but you will have to know how to use the functions # (so be sure to read the dCIA !) import random. import string WORDLIST FILENAME -“words.xt def load words) Returns a list of valid words. Words are strings of lowercase letters. Depending on the size of the word list, this function may take a while to finish print(“Loading word list from file…”) # inFile : file inFile open (WORDLIST FILENAME, ‘r) # line: string line inFile.readline () # Wakad dat : list of strings wordlist-line.split () print(“,len (wordlist) “words loaded.”) return wordlist def choose word (wordlist) list) list of words (strings) Returns a word from aast at random return random.choice (wordlist) # end of helper code # Load the list of words into the variable Wakamat # so that it can be accessed from anywhere in the program wordlist-load words () def is word quessed (secret word, letters quessed) secret_word: string, the word the user is guessing: assumes al1 letters are lowercase letters_guessed: list (of letters),which letters have been guessed so far: assumes that all letters are lowercase returns: boolean, True if all the letters of secret_word are in letters_guessed: False otherwise # FILL IN YOUR CODE HERE AND DELETE “pass” pass def get quessed word (secret word, letters quessed) secret_word: string, the word the user is guessing letters_guessed: list (of letters),which letters have been guessed so far returns: string, comprised of letters, underscores ,and spaces that represents which letters in secret word have been guessed so far, # FILL IN YOUR CODE HERE AND DELETE “pass” pass def get available letters (letters guessed) letters guessed: 1ist (of letters), which letters have been guessed so far returns: string (of letters), comprised of letters that represents which letters have not yet been guessed. # FILL IN YOUR CODE HERE AND DELETE “pass” pass def hangman (secret word) secret word: string, the secret word to guess Starts up an interactive game of Hangman At the start of the game, let the user know how many letters the secret word contains and how many guesses s/he starts with The user should start with 6 guesses Before each round, you should display to the user how many guesses Before each round, you should display to the user how many guesses s/he has left and the letters that the user has not yet guessed. Ask the user to supply one guess per round. Remember to make sure that the user putsin a letter! The user should receive feedback immediately after each guess about whether their guess appears in the computer’s word. After each guess,you should display to the user the partially guessed word so far Follows the other limitations detailed in the problem write-up. # FILL IN YOUR CODE HERE AND DELETE “pass” pass When you’ve completed your hangman function, scroll down to the bottom of the file and uncomment the first two lines to test (hint: you might want to pick your own secret word while you’re doing your own testing) et match withgaps (my wora, otherword) : – – my_ word: string with characters, current guess of secret word other word: string, regular English word returns: boolean, True if all the actual letters of my word match the corresponding letters of other word, or the letter is the special symbol , and my word and other word are of the same length; False otherwise: # FILL IN YOUR CODE HERE AND DELETE “pass” pass def show possible matches (my word): my_ word: string with characters, current guess of secret word returns: nothing, but should print out every word in dt that matches my word Keep in mind that in hangman when a letter is guessed, all the positions at which that letter occurs in the secret word are revealed Therefore, the hidden letter (cannot be one of the letters in the word that has already been revealed # FILL IN YOUR CODE HERE AND DELETE “pass” pass def hangman_with hints (secret_word): secret_word: string, the secret word to guess Starts up an interactive game of Hangman. At the start of the game, let the user know how many letters the secretword contains and how many guesses s/he starts with . The user should start with 6 guesses Before each round, you should display to the user how many guesses – s/he has left and the letters that the user has not yet guessed Ask the user to supply one guess per round. Make sure to check that the user guesses a letter The user should receive feedback immediately after each guess about whether their guess appears in the computer’s word After each guess,you should display to the user the partially guessed word so far If the guess is the symbol , print out all words in toxs that matches the current guessed word Follows the other limitations detailed in the problem write-up # FILL IN YOUR CODE HERE AND DELETE “pass” pass # When you’ve completed your hangman-with-hint function, comment the two similar # lines above that were used to run the hangman function, and then uncomment # these two lines and run this file to test! # Hint: You might want to pick your own secret word while you’re testing. ” main ame # pass # To test part 2, comment out the pass line above and # uncomment the following two lines. if _name-main”: # pass # To test part 2, comment out the pass line above and # uncomment the following two lines. secret word -choose word (wordlist) hangman (secret word) # To test part 3 re-comment out the above lines and # uncomment the following two lines. #secretword = chooseword (Wakaddst) #hangman with hints (secret word) – – Show transcribed image text # Problem Set 2, hangman . RY # Name: Sung Min ham # Collaborators: # Time spent: # Hangman Game # Helper code # You don ‘t need to understand this helper code, # but you will have to know how to use the functions # (so be sure to read the dCIA !) import random. import string WORDLIST FILENAME -“words.xt def load words) Returns a list of valid words. Words are strings of lowercase letters. Depending on the size of the word list, this function may take a while to finish print(“Loading word list from file…”) # inFile : file inFile open (WORDLIST FILENAME, ‘r) # line: string line inFile.readline () # Wakad dat : list of strings wordlist-line.split () print(“,len (wordlist) “words loaded.”) return wordlist def choose word (wordlist) list) list of words (strings) Returns a word from aast at random return random.choice (wordlist) # end of helper code # Load the list of words into the variable Wakamat # so that it can be accessed from anywhere in the program wordlist-load words ()
def is word quessed (secret word, letters quessed) secret_word: string, the word the user is guessing: assumes al1 letters are lowercase letters_guessed: list (of letters),which letters have been guessed so far: assumes that all letters are lowercase returns: boolean, True if all the letters of secret_word are in letters_guessed: False otherwise # FILL IN YOUR CODE HERE AND DELETE “pass” pass def get quessed word (secret word, letters quessed) secret_word: string, the word the user is guessing letters_guessed: list (of letters),which letters have been guessed so far returns: string, comprised of letters, underscores ,and spaces that represents which letters in secret word have been guessed so far, # FILL IN YOUR CODE HERE AND DELETE “pass” pass def get available letters (letters guessed) letters guessed: 1ist (of letters), which letters have been guessed so far returns: string (of letters), comprised of letters that represents which letters have not yet been guessed. # FILL IN YOUR CODE HERE AND DELETE “pass” pass def hangman (secret word) secret word: string, the secret word to guess Starts up an interactive game of Hangman At the start of the game, let the user know how many letters the secret word contains and how many guesses s/he starts with The user should start with 6 guesses Before each round, you should display to the user how many guesses
Before each round, you should display to the user how many guesses s/he has left and the letters that the user has not yet guessed. Ask the user to supply one guess per round. Remember to make sure that the user putsin a letter! The user should receive feedback immediately after each guess about whether their guess appears in the computer’s word. After each guess,you should display to the user the partially guessed word so far Follows the other limitations detailed in the problem write-up. # FILL IN YOUR CODE HERE AND DELETE “pass” pass When you’ve completed your hangman function, scroll down to the bottom of the file and uncomment the first two lines to test (hint: you might want to pick your own secret word while you’re doing your own testing) et match withgaps (my wora, otherword) : – – my_ word: string with characters, current guess of secret word other word: string, regular English word returns: boolean, True if all the actual letters of my word match the corresponding letters of other word, or the letter is the special symbol , and my word and other word are of the same length; False otherwise: # FILL IN YOUR CODE HERE AND DELETE “pass” pass def show possible matches (my word): my_ word: string with characters, current guess of secret word returns: nothing, but should print out every word in dt that matches my word Keep in mind that in hangman when a letter is guessed, all the positions at which that letter occurs in the secret word are revealed Therefore, the hidden letter (cannot be one of the letters in the word that has already been revealed
# FILL IN YOUR CODE HERE AND DELETE “pass” pass def hangman_with hints (secret_word): secret_word: string, the secret word to guess Starts up an interactive game of Hangman. At the start of the game, let the user know how many letters the secretword contains and how many guesses s/he starts with . The user should start with 6 guesses Before each round, you should display to the user how many guesses – s/he has left and the letters that the user has not yet guessed Ask the user to supply one guess per round. Make sure to check that the user guesses a letter The user should receive feedback immediately after each guess about whether their guess appears in the computer’s word After each guess,you should display to the user the partially guessed word so far If the guess is the symbol , print out all words in toxs that matches the current guessed word Follows the other limitations detailed in the problem write-up # FILL IN YOUR CODE HERE AND DELETE “pass” pass # When you’ve completed your hangman-with-hint function, comment the two similar # lines above that were used to run the hangman function, and then uncomment # these two lines and run this file to test! # Hint: You might want to pick your own secret word while you’re testing. ” main ame # pass # To test part 2, comment out the pass line above and # uncomment the following two lines.
if _name-main”: # pass # To test part 2, comment out the pass line above and # uncomment the following two lines. secret word -choose word (wordlist) hangman (secret word) # To test part 3 re-comment out the above lines and # uncomment the following two lines. #secretword = chooseword (Wakaddst) #hangman with hints (secret word) – –

Expert Answer


Answer to THIS IS PYTHON PROGRAMMING CODES TO COPY: # Problem Set 2, hangman.py # Name: Sung Min Lim # Collaborators: # Time spent… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *