Python Forum
Help with Python function? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help with Python function? (/thread-24072.html)



Help with Python function? - b_salm - Jan-29-2020

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?


RE: Help with Python function? - micseydel - Jan-29-2020

What have you tried?


RE: Help with Python function? - satyashetty - Jan-30-2020

Try writing the function def answer_score() & then if you get stuck people on the forum can help you