我应该在一个字符串中找到一个“你好”这个词,这是我从输入中给它的。这是我目前拥有的代码,但我无法将 'hello' 与字符列表匹配。mylist = 'it can be any letter plus hello in it'for letter in mylist: if letter in key: mylist2+=letterprint(mylist2)mylist2 = ['h', 'h', 'e', 'l', 'l', 'l', 'l', 'l', 'o', 'o']
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
这是我认为可以在字符串中找到“hello”字的代码。
firststring = input() #ahhellllloou
to_find = "hello"
def check_string(firststring, to_find):
c = 0
for i in firststring:
#print(i)
if i == to_find[c]:
c += 1
if c == len(to_find):
return "YES"
return "NO"
print(check_string(firststring, to_find))
添加回答
举报
0/150
提交
取消
