所以下面的代码给出了一个输入,检查输入是否是一个字符长,在过去的猜测中,看看它是否是一个字母。否则它应该返回消息再试一次。但是,在尝试代码时,我只得到 else 条件而无法得到 if 条件(应该返回结果)。任何人都知道为什么以及如何解决这个问题?def get_guess(past_guesses):"""Checks if past_guesses is 1 letter, a letter or has been used before, and prompts user to try againExample:>>> get_guess(['A', 'a', 'c', 'd'])'You need to enter one alphabetic character which you haven't\already guessed. Try again'>>> get_guess(['a', 'b', 'c', 'd'])'a'"""answer = "'You need to enter one alphabetic character which you haven't\already guessed. Try again'"while True: guess = input("Guess a letter: ") if guess.isalpha() and len(guess) == 1 and guess not in past_guesses: past_guesses.append(guess) return guess else: print (answer)
添加回答
举报
0/150
提交
取消