当我使用两个相同字母的单词(如“时髦”)时,猜测一次只激活一个字母。我怎样才能解决这个问题
l1=input('Input your (lowercase) letter:')
l2=input('Input your (lowercase) letter:')
l3=input('Input your (lowercase) letter:')
l4=input('Input your (lowercase) letter:')
l5=input('Input your (lowercase) letter:')
l6=input('Input your (lowercase) letter:')word=[l1,l2,l3,l4,l5,l6]
n1=''
n2=''
n3=''
n4=''
n5=''
n6=''
show=[n1,n2,n3,n4,n5,n6]
fail=0
good=0
while fail<=6 and good<6:
guess=input('Guess a letter...')
if guess in word:
print('Right!')
good=good+1
if guess==l1:
n1=guess
elif guess==l2:
n2=guess
elif guess==l3:
n3=guess
elif guess==l4:
n4=guess
elif guess==l5:
n5=guess
elif guess==l6:
n6=guess
show=[n1,n2,n3,n4,n5,n6]
else:
print('No.')
fail=fail+1
print(show)
print(word)
if fail==7:
print('Executioner wins!')
else:
print('Prisoner wins!')
为了澄清这一点,我不能两次猜出这封信来显示它的所有实例
好吧,代码中有很多东西不是最优的,但是这里有一个小的改进(这也是非最优的)。我使用for循环查找与猜测相符的所有字母
这对你有用吗
相关问题 更多 >
编程相关推荐