You can use Cramer’s rule to solve the following 2 x 2 system of linear equations: Ax+By=E
Cx+Dy=f
X=ED-Bf/AD-Bc
Y= Af-Ec/AD-Bc
Write a program that prompts the user to enter A, B, C, D, E, and F nd display the
result. If AD – BC is 0, report that “The equation has no solution”.
Do all you can to make your program structure when running, conform with the sample runs
given below:
Enter a, b, c, d, e, f: 9.0, 4.0, 3.0, -5.0, -6.0, -21.0
x is -2.0 and y is 3.0
Enter a, b, c, d, e, f: 1.0, 2.0, 2.0, 4.0, 4.0, 5.0
The equation has no solution
a,b,c,d,e,f = [float(i) for i in input("Enter a, b, c, d, e, f: ").split(',')]
diff = a*d-b*c
if diff!=0:
x=(e*d-b*f)/diff
y=(a*f-e*c)/diff
print(f"x is {x} and y is {y}")
else:
print("The equation has no solution")
Comments
Leave a comment