我想讓hang子手,我知道還有很多事情要做,但我無法弄清楚爲什麼底部的異常不起作用。這是我的代碼。爲什麼我的例外不起作用
import random
hideword = 0
player1 = input('''What is player 1's you name? ''')
player2 = input('''What is player 2's you name? ''')
letterlist = ['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']
print(player1 + 'is first!')
word = input(player2 + ', please turn away, ' + player1 + ' please write a LOWER case word for ' + player2 + ' to guess. ')
wordsplit = list(word)
while hideword < 50:
print()
hideword += 1
while True:
print(player2 + ', ' + player1 + ''''s word fits into these blanks''')
print('_ ' * len(wordsplit))
letter = input(player2 + ' please type a LOWER case letter to guess. ')
wordsplit.index(letter)
letterlist.remove(letter)
try:
if letter in wordsplit:
print('CORRET!')
print('_ ' * wordsplit.index(letter) + letter + ' _ ' * (len(wordsplit) - wordsplit.index(letter) - 1))
break
except ValueError:
print('Incorrect! Try again')
如果你的'try:except:'塊,那麼會導致'ValueError'? –