Reputation: 139
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
Upvotes: 0
Views: 925
Reputation: 53
Add a return
statement to tally
: change output_file()
to return output_file()
Upvotes: 3
Reputation: 781255
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()
Upvotes: 2