基本上我要做的就是做一个刽子手游戏。虽然我在比赛中扭曲了。我想做的是有程序
因此,如果用户输入“a”作为第一次尝试,则游戏将在其中找到所有带有“a”的单词并将其从列表中删除等等,这意味着您几乎总是会错过前4个元音。最终你会让程序坚持一个单词,因为没有一个有效的单词可以切换到没有用户已经选择的字母。
我的问题是,如何才能将所有删除的单词放入已删除的列表中?
# HANGMAN
import random
def main():
num_wrong=0
word_list=['car', 'road', 'truck', 'dog', 'desk', 'tree', \
'cat', 'zug', 'acu', 'python']
left=['a','b','c','d','e','f','g','h','i','j','k','l',\
'm','n','o','p','q','r','s','t','u','v','w','x',\
'y','z']
let_guessed=[]
let_unguessed=['a','b','c']
finished=False
r=random.randint(0,len(word_list)-1)
answer=word_list[r]
current='_'*len(answer)
show_status(current,num_wrong,left)
guess=input('Guess a letter: ')
while num_wrong<6 and not finished: # after 6 you lose
left.remove(guess)
if guess not in answer:
num_wrong+=1
print(guess,'is not in the word')
else: # if the guess is correct
print(guess,'is in the word')
# modify current
for z in range(len(answer)):
# check to see if we have an alphabetic at that spot already
if answer[z]==guess:
current=current[0:z]+guess+current[z+1:]
if answer==current:
print('You win!')
finished=True
show_status(current,num_wrong,left)
if not finished:
guess=input('Guess a letter: ')
def show_status(str1,x,letters):
for a in str1:
print(a+' ',end='')
print('You have made',x,'wrong guesses so far.')
print('The following letters are still available:')
str1=''
for each in letters:
str1+=each+' '
print(str1)
main()
答案 0 :(得分:3)
只需创建一个没有用户选择的字母的新列表:
word_list = [w for w in word_list if chosen_letter not in w]