Sorry if this has already been asked, I searched but didn't find anything.
I'm having some fun with odds, making a function that uses a list and random weighted results to simulate a race. I was wondering how I would summarize the results of x amount of races.
my code looks like this:
cars= ["Favorite", "Second", "Third", "Forth", "Fifth", "Sixth", "Seventh", "Eigth"]
def Race():
for i in range(100):
Winner = random.choices(Cars, weights=(33, 28.57, 14.285, 10, 8.33, 6.66, 4, 1.9), k=1)
print(Winner[0])
Race()
In this example, we have eight cars that are racing 100 times.
this prints a list of all of of the winners from each race. How would I get it to summarize how many times each outcome has resulted instead of getting a large list? For example, something like "Favorite won x times!", "Second won x times!", and so on. I tried using for statements but I wasn't quite sure what the heck I was doing lol.
I am new to python, in my first year in IT. please be gentle on me. Thanks!
Aucun commentaire:
Enregistrer un commentaire