Your code could benefit from an if __name__ == '__main__':
if __name__ == '__main__':
block. That way, you might later create a very fancy hangman game that imports this one to use its makeGallow
function. As it is, importing this would start the game. I would suggest that you define a main
function and call it in your if __name__ == "__main__":
block.
I see that you are using generator expressions. That's good, but actually a list comprehension is faster when using str.join()
a list comprehension is faster when using str.join()
. Even better, don't bother with either.
Your code could benefit from an if __name__ == '__main__':
block. That way, you might later create a very fancy hangman game that imports this one to use its makeGallow
function. As it is, importing this would start the game. I would suggest that you define a main
function and call it in your if __name__ == "__main__":
block.
I see that you are using generator expressions. That's good, but actually a list comprehension is faster when using str.join()
. Even better, don't bother with either.
Your code could benefit from an if __name__ == '__main__':
block. That way, you might later create a very fancy hangman game that imports this one to use its makeGallow
function. As it is, importing this would start the game. I would suggest that you define a main
function and call it in your if __name__ == "__main__":
block.
I see that you are using generator expressions. That's good, but actually a list comprehension is faster when using str.join()
. Even better, don't bother with either.
Whenever I start a review, I open up PEP 8, the Python style guide. That document is so rarely read that it is depressing. Your naming is not in accordance with it. From Method Names and Instance Variables:
Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.
(There's more, but it isn't pertinent here)
Your indentation looks good mostly, but for some reason you did eight-space indentation in makeGallow()
.
In makeGallow()
, you do a bunch of .append()
calls, but you don't guarantee that your list was empty in the first place. It is very easy to clear a list. Just do gallow[:] = []
. As long as you are doing something like that any way, you might as well do gallow[:] = [[] for _ in range(8)]
and take out your first for
loop. I used _
as my variable name instead of i
because it is the convention in Python to name a variable _
when you aren't using it.
Your code could benefit from an if __name__ == '__main__':
block. That way, you might later create a very fancy hangman game that imports this one to use its makeGallow
function. As it is, importing this would start the game. I would suggest that you define a main
function and call it in your if __name__ == "__main__":
block.
Strings are iterable. That can be useful when making a list of each character in it. For example, list("foo")
is ["f", "o", "o"]
. Therefore, you can change
secret_wordls = list()
for c in secret_word:
secret_wordls.append(c)
to
secret_wordls = list(secret_word)
and change
blanks = list()
for i in range(len(secret_word)):
blanks.append('_')
to
blanks = list("_" * letters)
Notice that I also changed len(secret_word)
to letters
. You defined the variable; why not use it? While I'm there, is letters
really a good name? From the name, I would expect it to be a list of characters or a string, not a number. Maybe word_length
would be better?
I see that you are using generator expressions. That's good, but actually a list comprehension is faster when using str.join()
. Even better, don't bother with either.
"".join(i for i in blanks)
could be
"". join(blanks)
for example.
I suggest that you add an elif len(letter) != 1
between if letter == "quit":
and the rest of the elif
s. That way, you can inform the user that he should type just one letter instead of penalizing him because what he typed isn't in your list of letters.
Th-th-th-th-that's all, folks! (Don't worry; it's a quotation.)