mercredi 29 août 2018

Python even group assigning

I am a beginner to python and was working on a random team generator. The issue I've run into is that I am not sure of how to make it generate even teams. The code is below as well as a sample output.

import random


def main():
    run = True
    while run:

        try:
            print("Welcome to this group picker, follow the instructions and your groups will be picked.")
            groupnum = int(input("How many groups do you want?"))
            peoplenum = int(input("How many people are there?"))
            print("Okay, assign everyone a number from 0 to", peoplenum - 1, ".")
            nums = []
            for i in range(0, peoplenum):
                nums.append(i)

            for i in nums:
                print("Number", i, "is in group", random.randint(1, groupnum))

            break

        except:
            print("Error, please follow instructions and enter only numbers.")
            break


main()

Sample output:

 Welcome to this group picker, follow the instructions and your groups
 will be picked.
 How many groups do you want?2 
 How many people are there?8
 Okay, assign everyone a number from 0 to 7 . 
 Number 0 is in group 1 
 Number 1 is in group 2 
 Number 2 is in group 1 
 Number 3 is in group 2 
 Number 4 is in group 1 
 Number 5 is in group 1 
 Number 6 is in group 2 
 Number 7 is in group 1




Aucun commentaire:

Enregistrer un commentaire