1

I am trying to have the user input call a function.

My code:

class the_proccess():

    the_route = input("Which function do you want to use? \n\n 1) The first one. \n\n 2) The second one. \n\n 3) The first one and then the second one. \n\n Please enter the corresponding number and hit enter >>>>> ")

    if the_route == 1:
        first()
    elif the_route == 2:
        second()
    elif the_route == 3:
        first()
        second()

    def first():
        print("First function")

    def second():
        print("Second function")

However, when I select the option the process stops. I'm not quite sure what I am doing wrong and this is my first time trying to do something like this.

Maverick
  • 789
  • 4
  • 24
  • 45

2 Answers2

3

Now this works as you want.

class the_proccess(object):

def first(self):
    print("First function")

def second(self):
    print("Second function")

def __init__(self):
    self.the_route = input("Which function do you want to use? \n\n 1) The first one. \n\n 2) The second one. \n\n 3) The first one and then the second one. \n\n Please enter the corresponding number and hit enter >>>>> ")

    if self.the_route == 1:
            self.first()
    elif self.the_route == 2:
            self.second()
    elif self.the_route == 3:
            self.first()
            self.second()

a = the_proccess();
Fra93
  • 1,992
  • 1
  • 9
  • 18
0

In this code, the variable the_route is a string because the input function returns a string. You could try

    if int(the_route) == 1:
Anonymous
  • 25
  • 6