I am trying to make a code to find x and y using two equations, my equation gives the right x and y but for some reason, it gives multiple 'There is no solution', and then multiple answers (ex x=3, y=4: 5 times).0 This is what I have so far: ''' Read in first equation, ax + by = c ''' a = int(input()) b = int(input()) c = int(input()) ''' Read in second equation, dx + ey = f ''' d = int(input()) e = int(input()) f = int(input()) solution_found = False for x in range(-10, 11):     for y in range(-10, 11):         eqn_1_solved = ((a * x + b * y) == c)         eqn_2_solved = ((d * x + e * y) == f)         if eqn_1_solved and eqn_2_solved:             solution_found = True             x_solution = x             y_solution = y          if solution_found:         print(f'x = {x_solution}, y = {y_solution}')     else:         print('There is no solution')

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

I am trying to make a code to find x and y using two equations, my equation gives the right x and y but for some reason, it gives multiple 'There is no solution', and then multiple answers (ex x=3, y=4: 5 times).0 This is what I have so far:

''' Read in first equation, ax + by = c '''
a = int(input())
b = int(input())
c = int(input())

''' Read in second equation, dx + ey = f '''
d = int(input())
e = int(input())
f = int(input())

solution_found = False
for x in range(-10, 11):
    for y in range(-10, 11):
        eqn_1_solved = ((a * x + b * y) == c)
        eqn_2_solved = ((d * x + e * y) == f)
        if eqn_1_solved and eqn_2_solved:
            solution_found = True
            x_solution = x
            y_solution = y
    
    if solution_found:
        print(f'x = {x_solution}, y = {y_solution}')
    else:
        print('There is no solution')

Expert Solution
Step 1: Determine an introduction for above query:

Your question concerns how to construct Python code to solve two equations with two unknowns. Your present code is nearly correct, but it has two problems:

  1. It does not handle the case where there are multiple solutions correctly.
  2. It prints "There is no solution" for all of the x and y values that it iterates over, even if there are solutions.
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education