Basically i'm making a multiple choice exam with 20 questions using a lists.
I have my 20 questions and 20 answers with an answer key
the program runs through the lists as it should and it prints the statements as it should but occasionally it will use the same answer choices for one question. I don't mind if it uses the same choices throughout other questions I just need it to use different answers during each individual question. I've tried random.shuffle() with .pop() but it deletes the list and I only make it through 5 questions before it sends back an error.
this is the code listed below
for words in range(len(DATASETS[0])): #This loops through each item in the list
tmp = "\nWhat is the proper procedure when %s" %DATASETS[0][words] #This is the variable used in my if statements
if DATASETS[3][words] == 'A': #This compares the data in my key to where the proper answer should lie in the choices
print(tmp)
print('a.)'+str(DATASETS[1][words])+'\nb.)'+random.choice(DATASETS[1])+'\nc.)'+random.choice(DATASETS[1])+'\nd.)'+random.choice(DATASETS[1]))
elif DATASETS[3][words] == 'B':
print(tmp)
print('a.)'+random.choice(DATASETS[1])+'\nb.)'+str(DATASETS[1][words])+'\nc.)'+random.choice(DATASETS[1])+'\nd.)'+random.choice(DATASETS[1]))
elif DATASETS[3][words] == 'C':
print(tmp)
print('a.)'+random.choice(DATASETS[1])+'\nb.)'+random.choice(DATASETS[1])+'\nc.)'+str(DATASETS[1][words])+'\nd.)'+random.choice(DATASETS[1]))
elif DATASETS[3][words] == 'D':
print(tmp)
print('a.)'+random.choice(DATASETS[1])+'\nb.)'+random.choice(DATASETS[1])+'\nc.)'+random.choice(DATASETS[1])+'\nd.)'+str(DATASETS[1][words]))
DATASETS[2][words] = input("Please choose carefully:").upper()
while DATASETS[2][words] != 'A' and DATASETS[2][words]!= 'B' and DATASETS[2][words] != 'C' and DATASETS[2][words] != 'D':
DATASETS[2][words] = input("Sorry that is not an option, please try again:").upper()
don't mind the notes, class requirements and what not if more info is needed I apologize and if this is to much info I also apologize
Aucun commentaire:
Enregistrer un commentaire