Я пытаюсь удалить определенное значение индекса для ran_word, но не могу этого понять.Python

Программы на Python
Anonymous
Я пытаюсь удалить определенное значение индекса для ran_word, но не могу этого понять.

Сообщение Anonymous »

Я пробовал использовать такие функции, как pop или delete, но не могу удалить определенный индекс, используя индекс другого списка. Вы можете увидеть, что я пытался сделать, в предпоследнем разделе. помогите пожалуйста, весь день ищу ответ, не знаю, что делать.
import random

print("welcome to hang man you have 5 guesses to get the word right good luck:")

words = "stage thought bath noxious zip crown unwritten quickest promise soft vague unruly fine weak film room pig passenger liquid unequaled short gaudy ticket imaginary engine positiontent productive plough year uncovered adorable subtract quarrelsome whole dust rare aquatic snow defeated"
words_list = words.split()
ran = random.choice(words_list)
ln = len(ran)
tries = 0
letters_guesed = []
correct_letter = []
ran_word = list(ran)
astr = list('_' * ln)
new = "".join(correct_letter)
lt = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

x = True
while x == True:
print(ran)
astr_str = ''.join(astr)
print("\n hears what you have so far", astr)
print("Here are the letters you have guessed so far:",letters_guesed)
person = input(" guess the letter of the word(once all letters are filled hit enter one more time):")

if person in lt:
if person not in letters_guesed:
if person not in ran_word:
letters_guesed.append(person)
tries += 1
if tries == 5:
print("you were wrong the right word was:", ran)
x = False

elif len(person) > 1:
print("\nplease input one letter at a time")

else:
print(person,"is aready guessed")

else:
print("\nnot a valid guess")

# needs to be fixed 38 - 48
if person in ran_word:
if person not in correct_letter:
ran_l = ran_word.count(person)
if person in ran_word:
index = ran_word.index(person)
correct_letter.insert(index, person)
for item in range(ran_l):
if person in ran_word:
index = ran_word.index(person)
astr.insert(index, person)
astr.pop(index)
print(index)

if ran == astr_str:
x = False
print("you are right the word was:", ran)


Подробнее здесь: https://stackoverflow.com/questions/783 ... gure-it-ou

Вернуться в «Python»