0

It has to be ad-bc Here is my code but it says that a aList is not defined

def findDeterminate(alist):
    value=0
    aList = [[a,b],[c,d]]
    for i in range (0, len(aList)):
        value = aList[0][1]*aList[1][2] - aList[0][2]*aList[1][1]

def main():
    a = str(input("what is your first value"))
    b = str(input('what is your second value'))
    c = str(input('what is your third value'))
    d = str(input('what is your fourth value'))
    return findDeterminate(aList)
djv
  • 15,168
  • 7
  • 48
  • 72
PattyIce
  • 1
  • 1
  • 1
  • The `for` loop does nothing, get rid of it. The `findDeterminate()` function does not return a value. The `str()` function creates strings, you want `float()` instead. The `aList` assignment should be moved to `main()`. – Dietrich Epp Oct 14 '14 at 17:27

2 Answers2

1

I won't solve this for you, but will give some hints:

  • There is no aList in main().
  • You've misspelt aList as alist in the definition of findDeterminate().
  • What's the purpose of the for loop?
  • A two-element list has no element at index 2.
  • You are not returning anything from findDeterminate().
  • main() has no special meaning in Python and is not called automatically.

(BTW, the determinant of a matrix is spelled "determinant" and not "determinate".)

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0
# Determinant of a 2x2 matrix
matrixG = [[2, 1],
           [3, 4]]

if len(matrixG) != 2 or len(matrixG[0]) != 2:
    print("Matrix should be 2x2 matrix only")
else:
    determinant = (matrixG[0][0] * matrixG[1][1]) - (matrixG[0][1] * matrixG[1][0])
    print(determinant)