Challenge: Using the file school_prompt.txt, if the character ‘p’ is in a word, then add the word to a list called p_words.
school_prompt = open('school_prompt.txt','r')
chars = school_prompt.read()
words = chars.split() # 重点:把每个单词转化到列表
p_words = list()
for word in words:
if 'p' in word:
p_words.append(word)
print(p_words)

这是一个挑战任务,要求使用school_prompt.txt文件,检查每个单词,如果单词中含有字符‘p’,则将其添加到名为p_words的列表中。
1万+

被折叠的 条评论
为什么被折叠?



