Question: Write a python program per the following specifications: 1. Populate an array(list) of size 50 randomly with only integers 0 and 1 2. Repeat step1
Write a python program per the following specifications: 1. Populate an array(list) of size 50 randomly with only integers 0 and 1 2. Repeat step1 n = 1000 times using either a while loop or a for loop At this point you should have a total of 50000 observations 3. Display the number of 0s (use the count() function from prior labs) 4. Display the number of 1s (use the count() function from prior labs) 5. Using the Binomial distribution formulas a. Display the expected mean (average) of the 1s == n*size*.5 b. Calculate and display the standard deviation (SD) NOTE: sd should be > 100 c. Display the range as follows: mean + SD mean - SD 6. Answer the question: is the total number of 1s from 4 above. within the range as calculated in 5.c by printing Yes if it is within the range calculated in 5c No if it is not 7. Display the n*size (== 50000) integers 50 integers per line That is, display the integers in myList 50 per line for 1000 lines See sample output 8. Display the average of all n*size == 50000 integers (should be < 1 by adding the answers from 3 and 4 above and divide by n*size
SAMPLE code Template (available in the source code tab Lab06Template.py MODIFY as needed )
# CSC120 # Lab 06 Binomial distribution import random # Initialize array myList = [] # empty a = 0 b = 1 size = 50 j = 0 i = 0 n =1000 # Populate the list (size == 50) with random integers 0 OR 1 do calculations #and repeat n times while (j < n): i = 0 while i < size : # populate the list of size 50 randNum = random.randint(a,b) myList.append(randNum) i = i +1 j = j + 1 # Display array size print("size of my array is :", len(myList)) # printmyArray 10 values per line k = 0 sub = [] while (k < len(myList) ): sub = myList[k: k+10] print("...",k, sub) k = k+10 ones = 33 #place holder code only FIX zeros = -8 # place holder code FIX print(" number of 1 is: ", ones) print(" number of 0 is: ", zeros) # mean and standard deviation (sd) calculations here #EXAMPLE ONLY mean = 100 # USE n*size*.5 sd = 5 print("=====================") print(' size of myList is ', len(myList)) print('mean of My List:', mean, " sd (standard deviation: ", sd) print (" mean +-sd: ",mean + sd, " " , mean - sd ) print ("the mean number of 1's is within mean +- sd ??? YES/NO ") # need to answer this # compare the number of 1s (variable zeros calculated above # to see if it is within the range mean sd.
Run the code to see the OUTPUT of the template
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
