You'll be refactoring your code to use classes and objects.
Convert your hangman function into a class that takes in the target word in the constructor. The convert_to_dictionary and display_current_guess functions become methods in the class while the get_target_word function remains outside the class.
NB: Methods are just functions that are part of a class.
Basically, your final code should have:
The get_target_word function which you call to get the target word that would be passed into the Hangman instance
The Hangman class consisting of a constructor that takes in only one argument: the target word
The convert_to_dictionary and display_current_guess functions become methods in the Hangman class.
The run method in the Hangman class that contains the logic for running the hangman game
The section of the code where you instantiate and run the game. This should look like this:
You'll be refactoring your code to use classes and objects.
Convert your hangman function into a class that takes in the target word in the constructor. The
convert_to_dictionary
anddisplay_current_guess
functions become methods in the class while theget_target_word
function remains outside the class.NB: Methods are just functions that are part of a class.
Basically, your final code should have:
get_target_word
function which you call to get the target word that would be passed into the Hangman instanceHangman
class consisting of a constructor that takes in only one argument: the target wordconvert_to_dictionary
anddisplay_current_guess
functions become methods in theHangman
class.run
method in the Hangman class that contains the logic for running the hangman gametarget_word = get_target_word() hangman = Hangman(target_word) hangman.run()