143k views
5 votes
Write a Python function called simulate_observations. It should take no arguments, and it should return an array of 7 numbers. Each of the numbers should be the modified roll from one simulation. Then, call your function once to compute an array of 7 simulated modified rolls. Name that array observations.

2 Answers

4 votes

Final answer:

The 'simulate_observations' Python function simulates rolling a six-sided die 7 times, storing the results in an array named 'observations'.

Step-by-step explanation:

To write a Python function called simulate_observations which returns an array of 7 simulated modified rolls, we can use the random module's randint function to simulate the rolling of a six-sided die. The code snippet below defines the function that generates 7 random numbers, each representing the outcome of a die roll, and stores them in an array called observations.

import random
def simulate_observations():
results = []
for _ in range(7):
roll = random.randint(1, 6)
results.append(roll)
return results
observations = simulate_observations()
print(observations)

Each number in the array would be between 1 and 6, representing each side of a fair, six-sided die. Note that the modification mentioned in the question is not specified, thus the standard roll result is used.

User Dolly Aswin
by
8.1k points
3 votes

Answer:

import random

def simulate_observations():

#this generates an array of 7 numbers

#between 0 and 99 and returns the array

observations = random.sample(range(0, 100), 7)

return observations

#here,we call the function created above and print it

test_array = simulate_observations()

print(str(test_array))

User Wreeecks
by
7.5k points