I have a system that makes random groups of 4, then rates them:
import numpy
import math
import random
for i in range(1):
# everything is in, see the indentation
members=4
n_groups =4
participants=list(range(1,members+1))*n_groups
#print participants
random.shuffle(participants)
with open('myfile1.txt','w') as tf:
for i in range(n_groups):
group = participants[i*members:(i+1)*members]
for participant in group:
tf.write(str(participant)+' ')
tf.write('\n')
with open('myfile1.txt','r') as tf:
g = [list(map(int, line.split())) for line in tf.readlines()]
print(g)
my_groups =g
def get_rating(group):
return len(set(group))
for each_grp in my_groups:
print((get_rating(each_grp)))
This gives the output:
[[1, 3, 2, 1], [4, 4, 3, 3], [2, 2, 1, 3], [1, 4, 4, 2]]
3
2
3
3
Is there a way I can sum the 4 ratings to get an overall score? Like in this case (3+2+3+3)=11, also if I change: for i in range(1): Which changes the amount of loops it does so: for i in range(5): Would run the code 5 times with different outcomes, is there a code to find the best overall score out of the 5 trials?
Basically Is there anything I can use to sum up the 4 ratings, then if repeated can it pick the best overall score out off all the repeats?
Aucun commentaire:
Enregistrer un commentaire