Python homework

MRAB python at mrabarnett.plus.com
Tue Dec 5 20:56:54 EST 2017


On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote:
> I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50
> times and then prints
> (i). the most frequent side of the die
> (ii). the average die value of all rolls.
> I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need.
> This is what I have so far:
> import random
> 
> def rollDie(number):
>      rolls = [0] * 6
>      for i in range(0, number):
>          roll=int(random.randint(1,6))
>          rolls[roll - 1] += 1
>      return rolls
> 
> if __name__ == "__main__":
>      result = rollDie(50)
>      print (result)
>      print(max(result))
> 
What is "rolls"? It's the number of times each side came up.

In the last line you asked it for the maximum number of times a side 
came up, and that's what you got.

You now just have to figure out _which_ side of the die that count 
corresponds to.



More information about the Python-list mailing list