为什么我的代码没有增加计数?

Why is my code not incrementing the count?

我有一个函数(来自我的部分代码),它应该在我 运行 函数时增加计数,但是,计数只保持在 1。我做错了什么?提前致谢。

def add_a_team():
    csv_team_count = 0
    team_adder = []
    csv_team_count += 1
    print(csv_team_count)

    if csv_team_count <4:
        for i in range(0,6):
            name = str(input("You are now entering the data for Team 1.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
            team_adder.append(name)

    else:
        print("Team count of 4 has been filled in! You cannot add another team!")

    print("\n")

    with open('teams.csv', 'a', newline = '', encoding='UTF8') as f:
        writer = csv.writer(f)
        #writing the data for each team.
        writer.writerow(team_adder)

    f.close()

每次初始化函数时,该值都设置为 0。

 csv_team_count = 0

在你递增到1之后,但如果你再次调用该函数,它将设置为0。这个值需要在函数外设置并作为arg传递。