1

I am very new to programming and im trying to call a method from one class to another class. I keep getting the error, "name 'quad' is not defined.

class problem(object):
    def ask(problem):
        problem = input("What type of problem are you trying to solve? 
Quadratic, ").capitalize() #add more
        if problem == "Quadratic":
            quad.equation()

class quadratic(object):    
    def equation():
        a = float(input('Enter a: '))
        b = float(input('Enter b: '))
        c = float(input('Enter c: '))


e = problem()
e.ask()
quad = quadratic()

The code isn't completely done as I am doing things one at a time, so anything helps.

I guess my question is, is there an easier way to call the method to the other class? Or am I just doing something wrong?

EDIT: I have since fixed my code. Thanks for helping.

Vshastra
  • 63
  • 7
  • What is `quad` supposed to be in `problem.ask`? – Patrick Haugh Dec 12 '18 at 04:04
  • Essentially I'm turning quad into the Quadratic class and from there I am trying to call to the equation function. – Vshastra Dec 12 '18 at 04:06
  • It looks like `quadratic.equation` should be a `staticmethod`, as it doesn't rely on an instance of the `quadratic` class. See: https://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod – Patrick Haugh Dec 12 '18 at 04:28

0 Answers0