You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a Hangman game created using object-oriented Python programming language (classes).
4
+
5
+
This game runs and can be interacted in a console.
6
+
7
+
By studying this code, you can learn how to apply classes and objects in your code, use "random" module to randomize values, and get a bit familiar of list comprehension.
8
+
9
+
This hangman game has 3 categories of words: fruit, vegetable, and animal. However, you can easily add more categories by following the examples in assign_words_for_category() function.
10
+
11
+
You can also configure how each difficulties as you want. The current list of difficulties includes easy, normal, and hard.
12
+
13
+
To create a class instance, you can start by taking a look at line 100th.
14
+
In this case, it is my_hangman = Hangman("fruit", "hard")
15
+
instance_name = class_name(argument(s))
16
+
The "my_hangman" is an instance, Hangman is a class, and "fruit" and "hard" are arguments.
17
+
The next 2 lines are function callings.
18
+
To start the game, we have to call these two functions namely welcome_message() to print out a welcome message, and start_the_game() to start the game.
19
+
20
+
Normally, when we want to call a function, we only need to type function_name(). However, in this case, the functions are in the class, so we have to "instance_name.function_name()" to call a function in a class.
21
+
22
+
Finally, you can learn more by looking at this code.
23
+
24
+
Also don't forget to "import random".
25
+
26
+
27
+
This is my second contribution in my entire life so far. If you don't mind, I want to showcase this in my portfolio.
0 commit comments