I just started coding (in Python 3) the day before yesterday (which makes me a SERIOUS beginner), and I realized that I would try to make my own Hangman game, but I just don’t know what happened to what I have done so far! ^ _ ^ This is it:
L = ["cat", "dog", "rabbit"]
from random import randrange
random_index = randrange(0,len(L))
w = L[random_index]
W = list(w)
a = input()
tries = 1
print(W)
while len(W) != 0 and tries<10:
if a in W:
print("yes")
W.remove(a)
tries += 1
a = input()
elif a not in W:
print("no")
tries += 1
a = input()
else:
if len(W) == 0:
print("Well done! Your word was")
print(w)
elif tries == 10:
print("You died!")
I think the problem comes from my thingy loop, and len (W)! = 0 ", because everything is fine with the input part, it just does not stop when it is needed! (that is, when it is assumed that there is nothing left to guess!) Therefore, I hope that someone will be good enough to spend two minutes of their day to help me with my main, not very interesting problem! Thanks in advance!
source
share