How Can I get this long code process to create 3 trials rather than one on a single run?
import numpy
import math
import random
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))
Usually the outcome would be:
[[2, 4, 1, 3], [3, 1, 2, 1], [3, 3, 4, 4], [2, 4, 1, 2]]
4
3
2
3
How could i get this to repeat the whole process n number of times so it gives something like (e.g. repeat 3 times):
[[3, 1, 2, 3], [4, 2, 1, 1], [2, 3, 1, 4], [4, 4, 3, 2]]
3
3
4
3
[[3, 1, 4, 1], [4, 3, 3, 4], [2, 2, 2, 2], [4, 1, 1, 3]]
3
2
1
3
[[3, 1, 3, 3], [4, 4, 4, 2], [1, 1, 2, 3], [2, 4, 1, 2]]
2
2
3
3
I could just copy the code 3 times but I was wondering if there was another way?
Aucun commentaire:
Enregistrer un commentaire