I'm currently making a questionnaire on csv and programming using python. I'm trying to make my code loop through the first column in my spreadsheet and to only print the questions which have the key corresponding to what the user has chosen in this case either 1 for earth or 2 for animals...
The following is the code i have so far but when i loop through this code it doesn't break if the number is not equal to 1. Also i have tried creating a variable which asks the user for the input on which subject they would like to pick. But when i run the program only the last question prints 5 times regardless if the user inputs 1 or 2, only the question at the bottom of the csv file is printed 5 times.
Here is my code!!
with open('questionnaire.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
key = row[0]
subject = row[1]
question = row[2]
option1 = row[3]
option2 = row[4]
option3 = row[5]
option4 = row[6]
prompt = "Which option do you pick? "
answer = row[7]
user_prompt = (f"" + question + "\n" + option1 + "\n" + option2 + "\n" +
option3 + "\n" + option4 + "\n" + prompt)
for key in row[0]:
if key == '1':
print(key)
else:
break
questionnaire = input(user_prompt)
