I've been trying to remaster my hangman game, but i ran into the problem
here's the problem
['p', 'l', 'a', 'n', 't', 's']
['*', '*', '*', '*', '*', '*']
Input ur guess : l
['*', 'l', '*', '*', '*', '*']
Input ur guess : t
['l', '*', '*', '*', 't', '*']
Input ur guess :
the first line of code is for easier viewing of my program
the problem is that the .remove
command removes the right element the first time, but not the 2nd time
i think theres a problem with the for loop colliding with the def()
creating different x's, hence the different values
here's the code
import random
words=["random","trees","plants"]
def gen_word():
global censored_word
picked_word=random.choice(words)
word=list(picked_word)
censored_word =["*"]*len(picked_word)
print(word)
print(censored_word)
input_func(word)
def input_func(word):
global censored_word
user_word=input("Input ur guess : ")
if len(user_word) > 1:
print("Ur input length is too long")
input_func()
return
for x in range(len(word)):
if user_word == word[x]:
censored_word.remove(censored_word[x])
censored_word.insert(x,user_word)
print(censored_word)
else:
continue
input_func(word)
return
gen_word()