assignment1-澳大利亚Python一对一教学「2」

AI悦创

共 1562字,需浏览 4分钟

 · 2022-05-12

5.5 process guess(guess: str, answer: str) -> str

Returns a modified representation of guess, in which each letter is replaced by:

  • A green square if that letter occurs in the same position in answer.

    • 如果该字母在答案中出现在同一位置,则为绿色方块。✅
  • A yellow square if that letter occurs in a different position in answer.

    • 如果该字母在答案中出现在不同的位置,则为黄色方块。✅
  • A black square if that letter does not occur in answer.

    • 如果该字母没有出现在答案中,则为黑色方块。✅

While answers must contain 6 unique letters, guesses may contain duplicate letters.

虽然 answer 必须包含 6 个独特的字母,但 guess 可能包含重复的字母。「answer 单词不重复」

If duplicate letters exist in the guess, only one can have a non-black square.

如果 guess 中存在重复的字母,只有一个字母可以有非黑色的方块(黄色或者绿色)。

If the letter does exist in answer, the non-black square is allocated as follows:

如果该字母在 answer 中存在,那么非黑色方块的分配方式如下。

  1. If one of the occurrences is in the correct position, it receives a green square and all other occurrences receive a black square.

如果其中一个出现在正确的位置上,它就会得到一个绿色的方块,其他的出现都会得到一个黑色的方块。✅

  1. Otherwise, if no occurrences are in the correct position, the first occurrence of the letter in guess receives a yellow square and all other occurrences receive a black square.

否则,如果没有出现在正确的位置上,guess 中的字母的第一次出现会得到一个黄色的方块,所有其他的出现会得到一个黑色的方块。

the second 'r' gets non-black square because it is in the right position

第二个 'r' 得到非黑色方块,因为它在正确的位置上。「第二个 ‘r'  得到绿色方块,因为在正确的位置 」

process_guess('arrows''strand')
🟨⬛🟩⬛⬛🟨

the first 'r' gets the non-black square because no r's are in the right postition but r exist in the answer.


第一个’r‘ 得到黄色方块,因为没有’r' 在正确的位置,但r存在于answer中

process_guess('arrows''answer')
🟩🟨⬛⬛🟨🟨

浏览 30
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报