Question: The following corresponds to PYTHON programming/ jupyter lab, please help answer SHORT parts a,b, and c. I will UPVOTE. Context: The following cell defines a
The following corresponds to PYTHON programming/ jupyter lab, please help answer SHORT parts a,b, and c. I will UPVOTE.
Context: The following cell defines a function, dice(), that you will use for below. The function dice() will randomly generate an integer number whenever you call it. The range of the generated random number is from 1 to 4. Run the cell so that the function can be used in the following cells.
from random import seed from random import random from time import time from math import ceil seed(time()) def dice(): a = ceil(random()*4) if a>0: return a else: return dice()
Here is how to use the function dice().
n = dice() print(n)
a) Write code to generate 100 random numbers ranging from 1 to 4 using the function dice(), and print them. Hint: Use a 'for' loop.
Confirm that it indeed generates a random integer between or equal to 1 and 4.
b) Write code that counts the occurrence of each number while you run dice() 100 times. Then print the occurrence of each number. Hint 1: Use a variable for each number to count the ocurrence while generating the random integers. Hint 2: Use a IF/ELIF/ELSE statement. For example, the example output would look like this: Number 1 occurred 22 times Number 2 occurred 30 times Number 3 occurred 27 times Number 4 occurred 21 times
c) Write code performing:
- Generate a random number using dice()
- Print a string using the following map
- If the generated number is 1, print '1 A'
- If the generated number is 2, print '2 T'
- If the generated number is 3, print '3 C'
- If the generated number is 4, print '4 G'
Hint: Use a IF/ELIF/ELSE statement. Complete code will look like this:
a = dice() if # complete the code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
