Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my code not incrementing the count?

I have a function (from a part of my code) which is supposed to increment the count whenever I run the function, however, the count only stays at 1. What am I doing wrong? Thanks in advance.

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()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Everytime you initialize the function the value is set to 0.

 csv_team_count = 0

After you increment to 1, but if you call again the function it will set to 0. This value needs to be set outside the function and be passed as arg.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading