(Algebra: solve 2 x 2 linear equations) You can use Cramer’s rule to solve the following 2 x 2 system of linear equation:
ax+by =e
cx+dy = f
Write a program that prompts the user to enter a, b, c, d, e, and f and display the result. If ad – bc is 0, report that The equation has no solution.
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
#enter a,b,c,d,e,f values
print("Enter a,b,c,d,e,f:")
a=eval(input())
b=eval(input())
c=eval(input())
d=eval(input())
e=eval(input())
f=eval(input())
#checking the condition ad-bc=0
#if the condition is true the statement will printed
if((a * d) - (b * c) == 0):
print("The equation has no solution")
#if the condition is false below code will be executed
else:
x=(e * d) - (b * f) / (a * d) - (b * c)
y=(a * f) - (e * c) / (a * d) - (b * c)
print(" x is",format(x,".1f"),"and y is ",format(y,".1f"))
OUTPUT:
Enter a,b,c,d,e,f:
1
2
3
4
5
6
x is 11.0 and y is -3.8
Enter a,b,c,d,e,f:
2
3
4
5
6
7
x is 15.9 and y is -0.4