Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Hangman/code.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import random # import random library

# method to draw hangman
def draw_hangman(i):
Graphics =['''_____\n|/ |\n| O\n| /|\\\n| / \\\n|''',
'''_____\n|/\n| O\n| /|\\\n| / \\\n|''',
'''_____\n|/\n| O\n| /|\\\n| /\n|''',
'''_____\n|/\n| O\n| /|\\\n|\n|''',
'''_____\n|/\n| O\n| /|\n|\n|''',

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand this part,

could you explain what this part does?

@imVivekGupta imVivekGupta Dec 13, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a list of hangman figures: see this commit - e40863b

Codeclimate marked this as an issue because the function length was 45 lines (<=25 lines guideline for good code). So, I modified to make it within limit.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure got it

'''_____\n|/\n| O\n| |\n|\n|''',
'''_____\n|/\n| O\n|\n|\n|''',
'''_____\n|/\n|\n|\n|\n|''',
'']
print(Graphics[i])

def pick_random_word():
# This function picks a random word from the SOWPODS dictionary.
Expand Down Expand Up @@ -76,8 +88,8 @@ def generate_word_string(word, letters_guessed):
word_string = generate_word_string(WORD, correct_letters_guessed)
print(word_string)
print("You have {} guesses left".format(num_guesses))

# tell the user whether they have won or lost
draw_hangman(num_guesses)
# tell the user whether they have won or lost
if num_guesses > 0:
print("Congratulations! You correctly guessed the word {}".format(WORD))
else:
Expand Down