本帖最后由 Arya 于 2021-4-20 15:39 编辑
有个循环题目,哪位大神能帮我看看吗?要求写一个function叫answer_mask(reo, attempt),然后通过测试如下表得出结果。我写的程序只能通过第1和3,通过不了2和4。代码和测试已经复制到附件。
def answer_mask(reo, attempt): """produce a string the same length as the reo string. Acharacter by charactercomparison is done between the stringsreo and attempt. If a character matchesthen a * character is used, if they do not match then the letter fromthe reo string is added.""" collect =' ' for i inrange(0,len(reo)): if reo ==attempt: collect +='*' else: collect +=reo returncollect
# test print(answer_mask("Ōtautahi","Otautahe")) print(answer_mask("Rāapa", "Rāpa"))
word = 'Aotearoa' print(answer_mask(word, word))
print(answer_mask("Tahi", "")) |