我创建了以下程序并导入了一个CSV文件,其中包含与常见手机问题相关的单词。我的问题是,它会选择“粉碎”,但不会因为逗号而选择“粉碎”。Python中的CSV文件没有给出确切的结果
所以,我的问题是,我怎样才能让它在没有逗号的情况下阅读这个词,而不是给我任何错误或任何东西?
任何帮助将不胜感激:)
import csv
screen_list = {}
with open('keywords.csv') as csvfile:
readCSV = csv.reader(csvfile)
for row in readCSV:
screen_list[row[0]] = row[1]
print("Welcome to the troubleshooting program. Here we will help you solve your problems which you are having with your phone. Let's get started: ")
what_issue = input("What is the issue with your phone?: ")
what_issue = what_issue.split(' ')
results = [(solution, screen_list[solution]) for solution in what_issue if solution in screen_list]
if len(results) > 6:
print('Please only insert a maximum of 6 problems at once. ')
else:
for solution, problems in results:
print('As you mentioned the word in your sentence which is: {}, the possible outcome solution for your problem is: {}'.format(solution, problems))
exit_program = input("Type 0 and press ENTER to exit/switch off the program.")
请自己展示你自己的尝试,并解释它为什么不起作用。 – martineau