Функция
Код: Выделить всё
randintКод: Выделить всё
random.randint(1, 6)Код: Выделить всё
randintThe output should be two columns. One displays all the sums (i.e. from 2 to 12) and the other displays the sums' respective frequencies in 1000 times.
My code is shown below:
Код: Выделить всё
import random
freq=[0]*13
for i in range(1000):
Sum=random.randint(1,6)+random.randint(1,6)
#compute the sum of two random numbers
freq[sum]+=1
#add on the frequency of a particular sum
for Sum in xrange(2,13):
print Sum, freq[Sum]
#Print a column of sums and a column of their frequencies
Источник: https://stackoverflow.com/questions/209 ... -frequency