Python Forum
Help with Python function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Python function?
#1
def main_questions():
    main_question = input("Would you like to take a short quiz?\n")
    if main_question == "Yes" or main_question == "yes":
        print("Lets start!\n")
        main_quesformat()
        print("\nThe Answers: 1)A 2)C 3)b\n")
        raise SystemExit()
    elif main_question == "No" or main_question == "no":
        print("Thanks for trying!")
        raise SystemExit()


question_prompts = [  # array
    "What color are apples?\n(a) Red/Green\n(b) purple\n(c) Orange\n\n",
    "What color are bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n",
    "What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n"
]

def main_quesformat():
    answer_list = ["a", "c", "b"]
    answer_choices = ["a", "b", "c"]  # The possible answers
    for single_question in question_prompts:
        while True:
            single_answer = input(single_question)
            if single_answer in answer_choices:  # Break the while loop if get a valid answer.
                break
            print("Your answer is not in: {}".format(answer_choices))
        answer_list.append(single_answer)  # Append the correct answer to the return list.
    return answer_list  # Return the all valid answers

def answer_score():
    

main_questions()
I am trying to create a function (answer_score) that will take the user imputed answers and calculate what they got out of the three answers. For example it would present: "You got x/3 answers." Having trouble with this. Help?
Reply
#2
What have you tried?
Reply
#3
Try writing the function def answer_score() & then if you get stuck people on the forum can help you
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020