Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 根据下一次输入中指示的编号输入并返回列表_Python - Fatal编程技术网

Python 根据下一次输入中指示的编号输入并返回列表

Python 根据下一次输入中指示的编号输入并返回列表,python,Python,再试一次 我正在尝试这样做,用户给出8个职业篮球队的名字,当被问到他们在nba的排名时,它会显示他们的位置,他们得到了多少圈。同时每8队倒换一次位置。也就是说,如果一个队是第一个选择,第八个队将在第九轮中第一个选择 nba = "" count = 1 teams = [] while count < 9: nba = input("enter nba team: ") count = count + 1 teams.append(nba) selection =

再试一次

我正在尝试这样做,用户给出8个职业篮球队的名字,当被问到他们在nba的排名时,它会显示他们的位置,他们得到了多少圈。同时每8队倒换一次位置。也就是说,如果一个队是第一个选择,第八个队将在第九轮中第一个选择

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: ")
nba=“”
计数=1
团队=[]
当计数小于9时:
nba=输入(“输入nba球队:”)
计数=计数+1
球队。附加(nba)
选择=输入(“这将进行多少轮?”)
打印(“团队订单为:”)
样品-

投入1:开拓者

投入2:湖人队

输入3:凯尔特人

输入4:热量

投入5:网络

投入6:勇士

输入7:cavs

输入8:微型飞行器

你要打多少回合?十一,

第一轮:开拓者

第二轮:湖人队

第三轮:凯尔特人

第四轮:热身赛

第五轮:蚊帐

第六轮:勇士队

第七轮:骑士队

第8轮:小牛队

第九轮:小牛队

第十轮:骑士队

第11轮:勇士队


如果这有点让人困惑,很抱歉。

你可以这样做:

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
因此,您的示例输出将是:

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

显然,此函数只是一个简单的示例。您可以更改它,以便通过输入问题设置
计数器。

实际上是您想要的。错误是什么?与其发布新问题,请用额外的细节编辑你以前的问题,我还以为另一篇文章在混合中迷失了方向。没关系。您想要实现的内容如果您编辑一个问题,它将自动显示为一个新问题。OP不想打印列表,他想在超过8轮时以特定的方式打印,请参考我的答案。@aj8uppal:谢谢!:D
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)
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