5. 16 LAB: Brute force equation solver

Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y = -1 have a solution x = 3, y = 2. Given integer coefficients of two linear equations with variables x and y, use brute force to find an integer solution for x and y in the range -10 to 10.


How do I write this in python?

Respuesta :

Use the knowledge of computational language in python to write a code that force to find an integer solution for x and y .

How to find the solution of an equation in python?

To make it simpler the code is described as:

def brute_force_two_equations(first_values, second_values,

                             max_range=10, min_range=-10):  

for x in range(-10, 10, 1):

   for y in range(-10, 10, 1):

      if a * x + b * y == c and d * x + e * y == f:

          print(x, y)

else:

   print('No solution')

def equation(const1, const2, x, y):

   return const1 * x + const2 * y

def get_three_integers():

   inputs = []

   for i in range(0, 3):

       inputs.append(int(input("Please enter a value: ")))

   return inputs

if __name__ == "__main__":

   print("== First Equation ==")

   first_equation_values = get_three_integers()

   print("== Second Equation ==")

   second_equation_values = get_three_integers()

   solution = brute_force_two_equations(first_equation_values,

                                        second_equation_values)

   if solution:

       print(f"(x, y) {solution}")

   else:

       print("No Solution found")

See more about python atbrainly.com/question/22841107

Ver imagen lhmarianateixeira