Answer to Question #292747 in Python for Hamza Zaidi

Question #292747

1. You have to write a program to check Pak-Studies exam. The exam has 40 MCQS. You have to store correct answers in a list.

1. A 2. C 3. A 4. A 5. D 6. B 7. C 8. A 9. C 10. B

11. A 12. D 13. C 14. A 15. D 16. C 17. B 18. B 19. D 20. A

21. A 22. C

23. A 24. A 25. D

26. B 27. C 28. A

29. C 30. B

31. A 32. D 33. C

34. A 35. D 36. C

37. B 38. B 39. D

40. A

Create another list and store student answers in it. Your program should check for correct answers. A student needs to answer 30 correct answers out of 40 to pass the exam. Your program must show whether the student has passed or failed the exam, the total number of correct answers, the total number of incorrect answers and a list of incorrect questions.



1
Expert's answer
2022-02-01T04:13:58-0500
def get_aswer(n):
    while True:
        ans = input("Get the answer on the " + str(n) + " question: ")
        ans = ans[0:1].upper()
        if ans in ['A', 'B', 'C', 'D']:
            return ans
        print("Incorrect answer, try again\n")


def ask_questions(n):
    L = []
    for i in range(n):
        ans = get_aswer(i+1)
        L.append(ans)
    return L


def check_answers(answers):
    correct_aswers = ['A', 'C', 'A', 'A', 'D', 'B', 'C', 'A', 'C', 'B',
                      'A', 'D', 'C', 'A', 'D', 'C', 'B', 'B', 'D', 'A',
                      'A', 'C', 'A', 'A', 'D', 'B', 'C', 'A', 'C', 'B',
                      'A', 'D', 'C', 'A', 'D', 'C', 'B', 'B', 'D', 'A']
    uncorrect = []
    for i in range(len(answers)):
        if answers[i] != correct_aswers[i]:
            uncorrect.append(i+1)
    return uncorrect


def main():
    answers = ask_questions(40)
    uncorrect = check_answers(answers)
    n_uncorr = len(uncorrect)
    n_corr = 40 - n_uncorr
    print()
    if n_corr >= 30:
        print("The examen was passed")
    else:
        print("The examen was not passed")
    print(f"There are {n_corr} correct and {n_uncorr} uncorrect answers")


    if (n_uncorr > 0):
        print("The uncorrect questions are:")
        for n in uncorrect:
            print(n, end=' ')
    print()


main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS