jeudi 24 août 2017

How can I create a random list with numbers?

Just trying to create a group system using student id's as numbers from 1-200, I have been using this code:

import random
members = 5
participants=[1,2,3,4,5,6,7,8,9,10,11]
random.shuffle(participants)
for i in range(len(participants) // members + 1):
    print('Group {} consists of:'.format(i + 1))
    group = participants[i*members:i*members + members]
    for participant in group:
        print(participant)

This works really well however I was going to use the numbers like to add or multiply the number in the group but gives me an 'int' error? Can anyone help? Thank you very much!1




Aucun commentaire:

Enregistrer un commentaire