title: How can I concatenate 2 variables, to call another variable of that combination?
body: <p>I have a defined function that includes a counter to know how many times it has been used, and asks for a user input of either L, R or F.
  I want it to then check the input and add it to the counter and call the function of that name.
  eg:
  user choose L
  count is at 3
  call function L3</p>
  <p>here is what I have so far, but I get an error:</p>
  <pre><code>def getUserDirection():
      getUserDirection.counter = 0
      getUserDirection.counter += 1
      direction = str(input(&quot;Which direction do you wish to go? (L/F/R) &quot;))
      direction = direction.upper()
      if direction not in (&quot;L&quot;, &quot;F&quot;, &quot;R&quot;):
          print(&quot;whats does {} mean? You were meant to type 'L', 'F' or 'R'! Try again..&quot;.format(direction))
          direction = getUserDirection()
      elif direction == &quot;L&quot;:
          print(direction()+counter())
      elif direction == &quot;F&quot;:
          print(direction()+counter())
      elif direction == &quot;R&quot;:
          print(direction()+counter())
      return getUserDirection()
  </code></pre>
  <p>The other functions I want it to call are:</p>
  <pre><code>def L1():
      print(&quot;you go left and see...&quot;)
  def F1():
      print(&quot;You continue forward and see...&quot;)
  def R1():
      print(&quot;You go right and see...&quot;)
  </code></pre>
  <p>The idea is to loop through <code>getUserDirection()</code> and call a different function with each pass. There will be plenty of functions as it progresses eg L1, L2, L3... each having a different story and new choice of direction to make.</p>
  <p>What am I doing wrong?</p>
  <p><strong>FULL CODE</strong></p>
  <pre><code>#PLAYER DETAILS
  first_name = input(&quot;What is your first name? &quot;)
  last_name = input(&quot;What is your last name? &quot;)
  while True:
      middle = input(&quot;Do you have a middle name? (y/n) &quot;)
      if middle.upper() not in (&quot;Y&quot;, &quot;N&quot;):
          print(&quot;whats does {} mean? You were meant to type 'y' or 'n'! Try again..&quot; .format(middle))
      elif middle.upper() == &quot;Y&quot;:
          middle_name = input(&quot;What is it? &quot;)
          break
      elif middle.upper() == &quot;N&quot;:
          middle_name = None
          break
  # is_middle_empty = bool(middle_name)
  # print(is_middle_empty)
  print(&quot;So your full name is {} {} {}? &quot;.format(first_name, '' if middle_name is None else middle_name, last_name))
  import time
  time.sleep(1)
  print(&quot;Hmmm..&quot;)
  time.sleep(1)
  just_first = str(input(&quot;Should I just call you {}? (y/n) &quot;.format(first_name)))
  if just_first.upper() == &quot;Y&quot;:
     player = first_name
     print(&quot;Great, nice to meet you&quot;, player)
  elif just_first.upper() != &quot;Y&quot;:
     name = first_name, &quot;&quot; if middle_name is None else middle_name, last_name
     player = &quot; &quot;.join(name)
     print(&quot;Sorry about that, let's stick to {} then.&quot; .format(player))
  print()
  
  #DIRECTION FUNCTION
  def getUserDirection():
      getUserDirection.counter = 0
      getUserDirection.counter += 1
      direction = str(input(&quot;Which direction do you wish to go? (L/F/R) &quot;))
      direction = direction.upper()
      if direction not in (&quot;L&quot;, &quot;F&quot;, &quot;R&quot;):
          print(&quot;whats does {} mean? You were meant to type 'L', 'F' or 'R'! Try again..&quot;.format(direction))
          direction = getUserDirection()
      elif direction == &quot;L&quot;:
          print(direction()+counter())
      elif direction == &quot;F&quot;:
          print(direction()+counter())
      elif direction == &quot;R&quot;:
          print(direction()+counter())
      return getUserDirection()
  
  
  
  #STORY LINES
  def start():
      print(&quot;You have arrived at ... To your left (L) is ..., ahead (F) is ... To your right (R) is ...&quot;)
  def L1():
      print(&quot;you go left&quot;)
  def F1():
      print(&quot;You continue forward&quot;)
  def R1():
      print(&quot;You turn right&quot;)
  
  #ADVENTURE-1
  adventure = input(&quot;So do you fancy a quick adventure? (y/n) &quot;)
  if adventure.upper() == &quot;Y&quot;:
      print(&quot;Great then lets set off...&quot;)
  elif adventure.upper() == &quot;N&quot;:
      print(&quot;Ah well, I guess we can't all be ubercool adventurers like me, fairwell {}, I hope we meet again some day.&quot; .format(player))
  
  #ADVENTURE-2
  time.sleep(1)
  print(start())
  print(getUserDirection())
  </code></pre>
  <p><strong>ERROR TRACEBACK</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\admin\PycharmProjects\pythonProject1\main.py&quot;, line 70, in &lt;module&gt;
      print(getUserDirection())
    File &quot;C:\Users\admin\PycharmProjects\pythonProject1\main.py&quot;, line 43, in getUserDirection
      print(direction()+counter())
  TypeError: 'str' object is not callable
  </code></pre>