Python 如何检查整个用户输入,而不仅仅是第一个单词
我试图通过用户输入进行检查,但它只检查第一个单词。关于如何让程序根据2D列表检查整个字符串,而不是只检查第一个单词并输出缺失的任何建议。 代码如下:Python 如何检查整个用户输入,而不仅仅是第一个单词,python,python-3.x,Python,Python 3.x,我试图通过用户输入进行检查,但它只检查第一个单词。关于如何让程序根据2D列表检查整个字符串,而不是只检查第一个单词并输出缺失的任何建议。 代码如下: my_list = [['noisey','pc','broken']['smashed','window','glass']] search = input('Enter what is going wrong: ') notfound = 'True' for i in mylist[0:1]: while notfound ==
my_list = [['noisey','pc','broken']['smashed','window','glass']]
search = input('Enter what is going wrong: ')
notfound = 'True'
for i in mylist[0:1]:
while notfound == 'True':
if search in my_list[0]:
print('Found in Pc')
notfound = 'False'
elif search in my_list[1]:
print('Found in Home.')
notfound = 'False'
else:
print('missing')
notfound = 'False'
这应该能奏效
#!/usr/bin/python3
my_list = [['noisey','pc','broken'],['smashed','window','glass']]
search = input('Enter what is going wrong: ')
for word in search.split():
if word in my_list[0]:
print(word,'Found in PC');
elif word in my_list[1]:
print(word,'Found in Home');
else:
print(word,"Not Found");
输出:
Enter what is going wrong: noisey pc smashed accidentally
noisey Found in PC
pc Found in PC
smashed Found in Home
accidentally Not Found
欢迎来到StackOverflow!尽管我们每个人都希望拥有某种超能力,但我们没有能力在互联网上阅读你的代码。请参阅。
$man it–没有手动输入它
抱歉,不确定“它”是什么…抱歉,我现在将添加它。我假设您的子列表在我的列表中
用逗号拆分