I’m having trouble getting this to work. Essentially I want a user to input a keyword and then get a question and answer pair as a return. The first, second, and third columns in the the spreadsheet has the keywords, while the fourth and fifth columns have the question and answer respectively. I want to have it so that the program only searches the first three columns for the keyword, and then only returns the 4th and 5th column from any row that contains that keyword.
So a user will put in the word “VPN”, the program will search the first 3 columns to see if any of them equal VPN. Let’s say the 1st row and 1st column equals VPN, then the program should return the question and answer columns from the first row.
I have code that searches all columns and returns all values from that column, but I’m having trouble with the specific rows and columns portion. Any help would be greatly appreciated!
scope =["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://ww$
creds = ServiceAccountCredentials.from_json_keyfile_name("key.json", scope)
client = gspread.authorize(creds)
sheet = client.open("Questionnaire").sheet1
userInput = input('Ask your question: ')
cell = sheet.find(userInput, in_column=[1-3]) #Not sure how to search multiple columns
rownum = cell.index(userInput) + 1
row = sheet.row_values(rownum) #Not sure how to return specific columns within this row
if cell != None:
print(row)
else:
print("I don't know the answer to that question")
Sophia Campione is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.