Question: Q6: write a python function randlist(k,n) to generate a list of random-length lists of integer sequences (i.e. list of lists) each starts at zero. The

 Q6: write a python function randlist(k,n) to generate a list ofrandom-length lists of integer sequences (i.e. list of lists) each starts atzero. The function accepts two parameters, k : the number of lists

Q6: write a python function randlist(k,n) to generate a list of random-length lists of integer sequences (i.e. list of lists) each starts at zero. The function accepts two parameters, k : the number of lists to be generated, and n : the maximum length of the list. Two sampl results from calling the function randlist(3,10) are: [[0, 1, 2], [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8]] [[0], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3]] In [ ]: 1 ## Q6 Answer 2. 3 def randlist(k, n): 4 generates a group of k random but even-length li 5 6 7 8 return randomlists 9 Q9: Using the listcoinflips(n) function you created above, write Python code to show the outcome of performing k trials, each consisting of flipping a coin n time, for any integers k and n. For example, the output of your code for n = 4 and k = 5 should be: [ trial 1 : ['H', 'H', 'H', ] trial 2 : ['H', 'H', 'T', 'T'] trial 3 : ['t', 'T', 'T', 'H'] trial 4 : ['H', 'T', 'H', 'H'] trial 5 : ['H', 'H', 'T', 'H'] In [ ]: 1 ## Q9 Answer 2 k 5 3 n 4 4 for j in range(k): 5 print(f'trial {j} : !) Q10: Write a new function called HTcount(n) that counts the heads and tails resulting from applying the listcoinflips (n) function you created above. For example, calling the function HTcount(100) can give the following answer in k = 100 trials, Heads 59 and Tails = 41 In [ ]: ## Q10 Answer 2 3 def HTcount(n): 4 returns two values H: the number of heads and T: the number from flipping a fair coin n times" 8 9 10 return H, T In [ ]: 1 ## Q10 test 2 k = 100 3 heads, tails print(f'in k HT count(k) {k} trials, Heads = {heads} and Tails = {tails}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!