def openFile():#calls open function import csv f = open("task2.csv", encoding="Latin1") csv_f = csv.reader(f) return(csv_f)
def extractRecords(csv_f): #calls for function records = [] for row in csv_f: records.append(row) return(records)
def userMenu():#calls print function while True: itemChoice = input("What Device is it ").lower()# allows upper and lower case answers to be accepted detailChoice = input("What's wrong with it? ").lower() choiceList = [] choiceList.append(itemChoice) # puts itemChoice at the end of the row choiceList.append(detailChoice) # puts detailChoice at the end of the row return(choiceList)
def findItem(records, choiceList, matchingWords, noOfMatchingWords, rowIndex): #Stores for and in function
for row in records:
for i in choiceList:
if i in row:
matchingWords.append(i)
if len(matchingWords) > noOfMatchingWords: # conditional on the length of a word
noOfMatchingWords = len(matchingWords)
matchingWords=[]
rowIndex = records.index(row)
if itemChoice =! choiceList
itemChoice = input("What Device is it ").lower()# allows upper and lower case answers to be accepted
detailChoice = input("What's wrong with it? ").lower()
userMenu()
findItem(records, choiceList, matchingWords, noOfMatchingWords, rowIndex)
else:
matchingWords = []
print( records[rowIndex][2])
Aucun commentaire:
Enregistrer un commentaire