python - Alternative to Using Expression as Variable? -
forgive me if question repeat, i'm stuck code i've been working on. creating program myself create random teams of people, , i've been trying find easy way make inserted amount of teams. area suck on here:
print("how many teams like?") numberteam = input("number: ") listnumber = 0 teams = [] while numberteam + 1: teams.append(team(str(listnumber + 1)) = [])
i new coder, i'm sure besides obvious using expression variable there other mistakes, suggestions on easy way fix great!
also if left out, please ask! (by way using python)
try (i cleaned things bit):
print("how many teams like?") numberteam = int(input("number: ")) # create dictionary, each team has emtpy list teams = dict([('team{}'.format(i), []) in range(numberteam)]) # following works # teams = {'team{}'.format(i):[] in range(numberteam)}
you can access teams this:
teams['team3'] # returns empty list
the longhand above is
print("how many teams like?") numberteam = int(input("number: ")) teams = {} in range(numberteam): teams['team{}'.format(i)] = []
Comments
Post a Comment