我創建了以下程序並導入了一個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