Question 1. Write a function called simulate that generates exactly one simulated value of your test statistic under the null hypothesis. It should take no arguments and simulate 50 area codes under the assumption that the result of each area is sampled from the range 200-999 inclusive with equal probability. Your function should return the number of times you saw the 781 area code in those 50 random spam calls.

Respuesta :

Answer:

The function written in python is as follows:

import random

def simulate():

    count = 0

    for i in range(1,51):

         num = random.randint(200,1000)

         if num == 781:

              count = count + 1

    print(count)

Step-by-step explanation:

This line imports the random library

import random

This line defines the function

def simulate():

This line initializes count to 0

    count = 0

This line iterates from 1 to 50

    for i in range(1,51):

This line generates random number between 200 and 999

         num = random.randint(200,1000)

This line checks if random number is 781

         if num == 781:

If yes, the count variable is incremented by 1

              count = count + 1

This line prints the number of times 781 is generated

    print(count)