0

Ok, I am new to programming and I'm making a python text game for a project in my computer science class.I need to call a function within another function. The only issue I'm having is that the inner function needs to be a parameter within the first so that I can change what function is being called.Here is the block of code that is the offender:

`def choosePath(a,b,c,d):
    path = ""
    path = input("Type "+a+" to "+a+" Type "+b+" to "+b+":")
    if path == a:
      c
    elif path == b:
      d
    elif path != a and path != b:
  choosePath(a,b,c,d)`

I need c and d to be function calls. I tried this with a print() statement but the print runs before anything else.

1 Answers1

0

You forgot the parentheses after the function calls.

def c():
    print('Calling function `c`')


def d():
    print('Calling function `d`')


def choosePath(a,b,c,d):
    path = ""
    path = input("Type "+a+" to "+a+" Type "+b+" to "+b+":")
    if path == a:
      c()
    elif path == b:
      d()
    elif path != a and path != b:
      choosePath(a,b,c,d)
Szabolcs
  • 3,990
  • 18
  • 38
  • 1
    Thanks. That solved my issue it worked exactly like I thought it should after adding the parentheses.TY for the help. – tcagle2077 Apr 07 '17 at 12:39