Hi! :)
I'm exercising with lists and dictionary by creating a test maker.
The point of the program is to be as dynamic as possible, meaning, the user can choose how many answers each question will have.
When I print the results I get the wrong answers near the question numbers.
What am I missing with the list/dictionary indexing? Is there more efficient way to get the right results?
code snippet:
here's a screenshot of the entire output:
![[Image: 5VCTs.png]](https://i.stack.imgur.com/5VCTs.png)
Thanks for your time.
again, this is not homework or any must assignment, this is just for me to stay in shape.
I'm exercising with lists and dictionary by creating a test maker.
The point of the program is to be as dynamic as possible, meaning, the user can choose how many answers each question will have.
When I print the results I get the wrong answers near the question numbers.
What am I missing with the list/dictionary indexing? Is there more efficient way to get the right results?
code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
def get_answers(): global answer choice_number = 0 try : choice_number = int ( input ( "Number of answers? " )) if choice_number > 4 or choice_number < 2 : print ( "Please select [2-4]" ) choice_number = 0 get_answers() except ValueError: print ( "Please select [2-4]" ) get_answers() for ans in range (choice_number): answer = input ( f "Answer {ans + 1}: " ) if len (answer) = = 0 : print ( "No empty answers." ) get_answers() question_answers.append(answer) answers.append(choice_number) print ( f "Number of answers: {answers}" ) print (question_answers) q_answers.append(answer) question_answers.clear() def get_right_answer(): right_answer = 0 try : right_answer = int ( input ( "Right Answer: " )) except ValueError: print ( "Value Error!" ) get_right_answer() if 0 < right_answer < = answers[ 0 ]: sure = input ( "Are you sure? [Y/n]: " ) if sure.lower() = = "n" : get_right_answer() elif sure.lower() = = "y" : question_right_answer[right_answer] = answer print ( f "Questions: {question_list}" ) print ( f "Right Answers: {question_right_answer}" ) print ( f "Total Score: {sum(scores)}" ) else : print ( "Please Select [Y/n]" ) get_right_answer() else : print ( f "Please select 1-{answers}" ) get_right_answer() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
def finish(): question_num = len (question_list) ask_continue = input ( "Do you wish to continue? [Y/n]: " ) if ask_continue.lower() = = "y" : answers.pop() main() finish() elif ask_continue.lower() = = "n" : print ( "\n\n==============RESULTS==============\n" ) print ( "#\t Question\t Answer\t Score" ) for i in range (question_num): print ( f "{i+1}\t {question_list[i]}\t\t {answer}\t\t {scores[i]}" ) i + = 1 else : print ( "Please select [Y/n]" ) finish() if __name__ = = "__main__" : global answer scores = [] question_list = [] q_answers = [] answers = [] question_answers = [] question_right_answer = {} question = input ( "Enter your question: " ) score = int ( input ( "Enter question score: " )) main() finish() |
![[Image: 5VCTs.png]](https://i.stack.imgur.com/5VCTs.png)
Thanks for your time.
again, this is not homework or any must assignment, this is just for me to stay in shape.