0

I'm very new to coding and I don't know how everything works in Python. I know this code isn't write but I need to know how to do these things.

    #Write a program that prompts the user to enter six points and use Cramer's rule to solve 2x2 linear equations.
    a, b, c, d, e, f = float(input("Enter a, b, c, d, e, f: "))

    if a*d-b*c==0:
        print("The equation has no solution.")
    else:
        x= ((e*d-b*f) / (a*d-b*c))
        y= ((a*f-e*c) / (a*d-b*c))
        print("X is: " , x , "and Y is: " , y) 

2 Answers2

2

You are converting the whole string to a float instead of each separate number. That is, you convert "1 3 5 2 3 6" to a float which doesn't work. I think what you mean is:

a, b, c, d, e, f = map(float, input("Enter a, b, c, d, e, f: ").split())

Using .split() means it will convert the string to a list of number strings. map(float, ...) will return a list of each number string converted to float.

zondo
  • 19,901
  • 8
  • 44
  • 83
1

Your method of collecting input is incorrect, and x and y need to be converted to strings when being printed.

a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))
d = float(input("Enter d: "))
e = float(input("Enter e: "))
f = float(input("Enter f: "))

if a*d-b*c==0:
    print("The equation has no solution.")
else:
    x= ((e*d-b*f) / (a*d-b*c))
    y= ((a*f-e*c) / (a*d-b*c))
    print("X is: " , str(x), "and Y is: ", str(y))
TimRin
  • 77
  • 7