Python: Solve the specified equation

Python Basic - 1: Exercise-35 with Solution

Write a Python program which solve the equation:
Print the values of x, y where a, b, c, d, e and f are given.

a,b,c,d,e,f separated by a single space.
(-1,000 ≤ a,b,c,d,e,f ≤ 1,000)

Sample Solution:

Python Code:

print("Input the value of a, b, c, d, e, f:")
a, b, c, d, e, f = map(float, input().split())
n = a*e - b*d
print("Values of x and y:")
if n != 0:
    x = (c*e - b*f) / n
    y = (a*f - c*d) / n
    print('{:.3f} {:.3f}'.format(x+0, y+0))

Sample Output:

Input the value of a, b, c, d, e, f:
 5 8 6 7 9 4
Values of x and y:
-2.000 2.000


Flowchart: Python - Solve the specified equation

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check whether three given lengths (integers) of three sides form a right triangle.
Next: Write a Python program to compute the amount of the debt in n months.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Checks if the given number falls within the given range.


def tips_range(n, start, end = 0):
  return start <= n <= end if end >= start else end <= n <= start
print(tips_range(2, 4, 6))
print(tips_range(4, 8))
print(tips_range(1, 3, 5))
print(tips_range(1, 3))