Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING THE PYTHON PROGRAMMING LANGUAGE You forgot to study for the final exam! Oh

ID: 3590053 • Letter: U

Question

USING THE PYTHON PROGRAMMING LANGUAGE

You forgot to study for the final exam! Oh no. There's some good news and some bad news. The good news is that the exam is multiple choice: 35 questions, each with 5 choices. So you have some chance at guessing correctly. The bad news is that you have to get at least 11 questions correct to pass the class. (Obviously, this final exam is too easy to be given by the math department.) What is the probability that you pass'? Write a program to estimate this probability, by simulating 1,000,000 exams. Specifically, the following should be executed in a loop, which executes a million times To represent a student's attempt at taking the exam, the program should generate 35 random numbers, each between 1 and 5. We will let the value 5 represent a correct answer - after all, the probability of getting a 5 is the same as the probability of guessing correctly (20%). The program should tally the number of correct answers, and decide if this exam is a pass or a fail, based on whether there are 2 11 correct answers or not number of number of trials number of passes 1000000 passes The probability should be approximately equal to should print out NOTE: if your program is working correctly, you should get DIFFERENT answers each time you run it, although the probability should be close to the same each time you run it Specifications: your program must This value is what your program » NOT ask the user for any input » print out an estimate of the probability that a student blindly guessing on a 35 question multiple choice exam, each question with 5 answer choices, gets at least 11 questions correct » use a simulation with random numbers - no credit for theoretical solutions. If you get the point of this assignment, it should be clear that your answers should not be exactly the true probabilities, and that it should not even give the same answer each time you run it Challenge (optional): keep track of all the scores. Print a histogram of the results - which (by the Central Limit Theorem) should be roughly normal - and calculate the (sample) standard deviation

Explanation / Answer

import random
countPass = 0;
for i in range(1000000):
   countCorrect = 0;
   for j in range(35):
       value = random.randint(1,5)
       if value == 5:
           countCorrect = countCorrect + 1

   if countCorrect >= 11:
      countPass = countPass + 1

print(countPass/1000000)v