Nov-28-2020, 04:00 AM
I see, you have at least two problems with the shown code.
1) your exception check in
2) Once you fix that, line 69 is
3) your printout from line 103 is
An example of looping until you get a valid response:
1) your exception check in
get_right_answer()
should only be a couple lines long, but the rest of the function (lines 63-80) is in that block, so it can't get executed if the answer is input properly.2) Once you fix that, line 69 is
question_right_answer[right_answer] = answer
. You're assigning "answer", not "right_answer". That seems wrong to me.3) your printout from line 103 is
print(f"{i+1}\t {question_list[i]}\t\t {answer}\t\t {scores[i]}")
. Note all the columns depend on i
except for the third. That one is just the bare answer
, so it will be the same for every line. An example of looping until you get a valid response:
valid = "no" while not valid.startswith(("y", "Y")): right_answer = int(input("Right Answer: ")) if 0 < right_answer <= answers[0]: valid = input("Are you sure? [Y/n]") valid = valid or "Y" else: print(f"Please select 1-{answers}") # We don't pass this point until user affirms answer is okay. This # separates the input code from the other tasks. # print the right answer to the screen for the user to see # store the right answer for later use..