vendredi 21 octobre 2022

Trying to make a program that randomises teams acording to user input (amount of teams and names of all participants) these will then be equal in size

I need to make a program where the user inputs all students names (this is then converted into a list each name becomes an item) and y amount of teams, the program will then randomize the teams with the names of the students. Ex. The user chooses 2 teams and has 4 different students the program then spits out 2 randomized teams with 2 students in each (these cannot be the same students).

import random
import os

#clears the screen
os.system('cls')

#creates the list that later is filled with user input
list_name = []

temp_name = ""

#team_total is the user choosen amount of teams, this is then converted into integer
team_total = input("How many teams do you want?\n")
team_total = int(team_total)

#makes it so that all names written by the user are converted to individual list items
name = input("What are your students names?:\n")
for x in name:
    if x == " ":
        list_name.append(temp_name)
        temp_name = ""
        continue
    else:
        temp_name = temp_name + x
list_name.append(temp_name)

#using len to create varible that is equivilant to the amount of items in list_name
y = len(list_name)

#team_size is the amount of people in each team (amount of teams divided by amount of students)
team_size = (y / team_total)

print(f"There will be {team_size} per team!")




#r1 is the student in team_1 
r1=random.randint(0,int(y))
team_a = (list_name[r1])

#r2 is the student in team_b (this also makes it so that r2 cant be the same as r1)
r2=random.randint(0,int(y))
while r2 == r1:
    r2 = random.randint(0,(y))
    r2=random.randint(0,int(y))
team_b = (list_name[r2])

This is how far I've gotten, I am completely stuck so help would be appriciated!




Aucun commentaire:

Enregistrer un commentaire