I am trying to create a function that every time it is called, it will generate a list of 100 random rolls of a die using the random library.
import random
def dice():
dado = []
for i in range(100):
dado.append(random.choice(range(1,7)))
return dado
dice()
When I run the function, it only returns one value. On the other hand, when I do this:
def dice():
dado = []
for i in range(100):
dado.append(random.choice(range(1,7)))
print(dado)
It returns 100 lists. The first contains one number, the next two, and so on until the list 100 with 100 numbers is printed. As I pointed out, what I want is for a single list of 100 random numbers to be printed.
I want to point out that I am also interested in the fact that the resulting list can be plotted through a histogram, for example.
Any help or guidance is greatly appreciated. Thank you!
The error is in the "dice()" function, the return should have one less tab, so that it is returned when the loop ends.
I leave you an example in this link click
Dice rolls, you can take it as a sequence of random events, without complicating the problem by adding conditional probability, you could use the python library
random
: