У вас есть несколько проблем, но главная из них заключается в том, что вы не вызываете функции, поэтому вы сравниваете саму функцию с секретом.
Код с исправлениями:
secret_word = 'tracy' # Don't make secret_word_list, there's no point; just use the str itself since you only test len 1 strings against it anyway
print secret_word
def get_guess(guess): # Don't make the default call input, that'll prompt once for an input and store it as the permanent default
while True:
# Test each condition and break loop only if all past; original code would never
# recheck length if new value entered after testing isalpha
if len(guess) != 1:
print "Your guess must be exactly one character!"
elif not guess.islower(): # Add missing call parens on islower; use not, never compare to False; islower implicitly verifies isalpha, so avoid testing isalpha
print "Your guess must be a lowercase letter!"
else:
break # Passed all tests, break loop
# Get new guess if any test failed
guess = raw_input("Guess: ") # Use raw_input on Python 2, never input (which eval's the result of raw_input)
# Removed else (loop always ends by breaking, using else nonsensical but harmless in original code too
return guess
while True:
# Move guess getting to if, because having it in else case never actually checked it
if get_guess(raw_input("Guess: ")) in secret_word:
print "That letter is in the secret word!"
else:
print "That letter is not in the secret word!"
Попробуйте онлайн!
Примечание. Я сохранял своеобразное странное поведение, когда get_guess
принимал аргумент, но затем повторял за догадки при неудаче. Более разумным решением было бы полностью удалить аргумент guess
и переместить guess = raw_input("Guess: ")
в начало цикла while
(удалив блок else
в конце).