-1

I want to call the function A() based on the userinput

def main_func():
    def A():
        print("A")
    i = 0
    userinput = input(": ")
    letter = userinput.split()
    number = len(letter)
    while (i < number):
        letter[i]()
        i = i + 1


main_func()

thanks in advance!

1 Answers1

0

First of all, you should put the printing function def A() outside your original function since it runs separately. Furthermore it is better to use a for loop instead of a while loop here. The following more simple code should work for you.

def A(letter):
        print(letter)

def main_func():
    userinput = input(": ")
    for letter in userinput:
        A(letter)

main_func()

Here your main function calls your A() function for every letter in the userinput. It also gives the function the specific letter as a parameter. The function A() then receives the parameter and prints it. Hope this helps

Kennos
  • 227
  • 1
  • 6