user3681641
user3681641

Reputation: 11

Inputting and getting back a list depending on the number indicated in the next input

Trying this one more time..

I am trying to make it so the user gives 8 names of professional basketball teams and when asked what ranked they are in a nba selection it shows their position for how many turns they get. while reversing the position every 8 teams. I.E if one team is first selection the 8th team will be first to select in the 9th round.

nba = ""
count = 1
teams = []
while count < 9:
    nba = input("enter nba team: ")
    count = count + 1
    teams.append(nba)
selection = input("how many rounds will this go to? ")
print("The team order is: ")

sample -

input 1: blazers

input 2: lakers

input 3: celtics

input 4: heat

input 5: nets

input 6: warriors

input 7: cavs

input 8: mavs

How many rounds are you going to? 11

round 1: blazers

round 2: lakers

round 3: celtics

round 4: heat

round 5: nets

round 6: warriors

round 7: cavs

round 8: mavs

round 9: mavs

round 10: cavs

round 11: warriors

etc

sorry if this is a little confusing.

Upvotes: 1

Views: 37

Answers (2)

Dair
Dair

Reputation: 16240

def print_rounds(rounds, team, cur_round=1):
    if rounds < len(team): #Handle the case when rounds is less than what is left.
        for i in team[:rounds]:
            print "Round: ", cur_round,
            print i
            cur_round += 1
        return
    for i in team:
        print "Round: ", cur_round,
        print i
        cur_round += 1
    rounds -= len(team)
    print_rounds(rounds, team[::-1], cur_round=cur_round) #Recursive call with the team list reversed.

teams = ["Blazers", "Lakers", "Celtics", "Heat", "Nets", "Warriors", "Cavaliers", "Mavericks"]

print_rounds(20, teams)

Produces:

Round:  1 Blazers
Round:  2 Lakers
Round:  3 Celtics
Round:  4 Heat
Round:  5 Nets
Round:  6 Warriors
Round:  7 Cavaliers
Round:  8 Mavericks
Round:  9 Mavericks
Round:  10 Cavaliers
Round:  11 Warriors
Round:  12 Nets
Round:  13 Heat
Round:  14 Celtics
Round:  15 Lakers
Round:  16 Blazers
Round:  17 Blazers
Round:  18 Lakers
Round:  19 Celtics
Round:  20 Heat

Upvotes: 1

JoshieSimmons
JoshieSimmons

Reputation: 2791

You could cook up something like this:

teams = ["Blazers", "Lakers", "Celtics", "Heat", "Nets", "Warriors", "Cavaliers", "Mavericks"]

def print_next(your_team_list):
    counter = 1
    current_index = 0
    for i in range(len(teams)):
        print "Round " + str(counter) + ": " + your_team_list[i]
        counter +=1

So your sample output would be:

Round 1: Blazers
Round 2: Lakers
Round 3: Celtics
Round 4: Heat
Round 5: Nets
Round 6: Warriors
Round 7: Cavaliers
Round 8: Mavericks

Obviously, this function is just a simple illustrative example. You could change it so that counter is set by your input question.

Upvotes: 0

Related Questions