0

This is my code for reference

def tally(tournament_results):

    results = tournament_results.split("\n")

    if results != ['']:
        for i in results:
            entry = i.split(";")
            if entry[0] not in teams:
                create_team(entry[0])

            if entry[1] not in teams:
                create_team(entry[1])

            if entry[2].strip() == "win":
                result(entry[0], entry[1], 'decision')
            elif entry[2].strip() == "loss":
                result(entry[1], entry[0], 'decision')
            elif entry[2].strip() == "draw":
                result(entry[0], entry[1], 'draw')

    output_file()


def output_file():
    global teams
    sorted_x = sorted(teams.items(), key=lambda teams: teams[1][4], reverse=True)
    result = template.format("Team", "MP", "W", "D", "L", "P")
    for entry in sorted_x:
        result = result + "\n" + (template.format(entry[0], entry[1][0], entry[1][1], entry[1][2], entry[1][3], entry[1][4]))

    teams = {}

    print(result)
    return result

if __name__ == '__main__':
    print(tally('Allegoric Alaskans;Blithering Badgers;win\n'
                   'Devastating Donkeys;Courageous Californians;draw\n'
                   'Devastating Donkeys;Allegoric Alaskans;win\n'
                   'Courageous Californians;Blithering Badgers;loss\n'
                   'Blithering Badgers;Devastating Donkeys;loss\n'
                   'Allegoric Alaskans;Courageous Californians;win'))

The print statement accurately prints the expected output which is:

Team                           | MP |  W |  D |  L |  P 
Devastating Donkeys            |  3 |  2 |  1 |  0 |  7 
Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6 
Blithering Badgers             |  3 |  1 |  0 |  2 |  3 
Courageous Californians        |  3 |  0 |  1 |  2 |  1 

However, my return value for the same variable is None. I don't quite understand why.

Any help would be appreciated

3
  • 1
    Show the code that's printing the return value. Commented Mar 17, 2019 at 16:29
  • @Barmar I added the code you requested Commented Mar 17, 2019 at 16:34
  • @Barmar oof I'm dumb. Thanks! I can put your as correct solution if you post as answer Commented Mar 17, 2019 at 16:38

2 Answers 2

3

Add a return statement to tally: change output_file() to return output_file()

Sign up to request clarification or add additional context in comments.

Comments

2

You're never printing the result of output_file(). You're printing the result of tally(), but it doesn't return anything. If you want that to print the result of output_file(), change:

output_file()

to:

return output_file()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.