【发布时间】:2021-09-08 22:47:22
【问题描述】:
`
#Problem 1
# #inputs
rack=input("what are the characters in your rack?: ")
word=input("what word would you like to create?: ")
#converting the rack to list
rack_list=[]
rack_list[:0]=rack
#Converting word to list
word_list=[]
word_list[:0]=word
#deleting whatever letters word has in it from rack list
for char in rack_list:
if char ==word_list:
word_list.remove(char)
#seeing if there are no more letters left in wordlist the word can be created
if len(word_list)==0:
can_make_word_bool=True
else:
can_make_word_bool=False
print(can_make_word_bool)
` 如果单词可以生成,can_make_word_bool 值将返回 true,如果无法生成,则返回 false。我这样做是为了如果用户在机架列表中有这些字母,单词中的任何字母都会从单词列表中删除。如果 word_list 的长度在末尾为 0,这应该意味着这个词可以拼写出来吗?由于某些原因,这些字母没有从单词列表中删除
【问题讨论】:
标签: python coding-style