0

I made a simple function to identify the tennis player who served the last point in a tie-breaker match. Below is my code, which returns the player but when I am printing the result, I get None.

def get_tie_break_point_server(s,tie_break_sum,playerA,playerB):

  s = s+1
  if(s == tie_break_sum):
      return playerB
  s = s+1
  if(s == tie_break_sum):
      return playerB
  else :
      get_tie_break_point_server(s,tie_break_sum,playerB,playerA)

tie_break_score = [2, 2]
playerA = "A"
playerB = "B"
tie_break_sum = tie_break_score[0] + tie_break_score[1]
print get_tie_break_point_server(1,tie_break_sum,playerA,playerB)
user2709885
  • 413
  • 2
  • 8
  • 16
  • 2
    Related questions: [Why does my recursive function return "None"?](http://stackoverflow.com/q/17286808), [Recursive function returning none?](http://stackoverflow.com/q/31739963), [Why Python recursive function returns None](http://stackoverflow.com/q/31221826), etc. – Martijn Pieters Aug 12 '15 at 12:40

1 Answers1

4

Your function returns None when it reaches the last 'else' block. When a function reaches the end of its code block without an explicit return statement it will implicitly return None. You need to change the last line to

return get_tie_break_point_server(s,tie_break_sum,playerB,playerA)
dsh
  • 12,037
  • 3
  • 33
  • 51