Hi there
My Algebra 2 class just started matrices, and I don't want to go out and pay $100 for a graphing calculator, just for the matrices, when I can code one myself. So... this is my code, and I can do it without classes, but I decided to make things more tidy for myself. It's very basic for now, just defines two different 2x2 matrices, but I'm going slow so I don't screw up. The code works fine by itself, but if I put the functions in a class, I get an error. Here's the code:
#####################################
# I follow the matrices as such:
# matrix A =
# [ 1_1 1_2 1_3 ]
# [ 2_1 2_2 2_3 ]
# [ 3_1 3_2 3_3 ]
# [ 4_1 4_2 4_3 ]
# so on
print 'Simple Matrix Calculator'
print ''
print 'Enter the following:'
print '\'1 for Entering a matrix'
print ' \'1 for a 2x2 matrix'
print ' \'1\' for matrix A'
A = 0
B = 0
class matrix_2x2_define:
def A(A):
print 'First row, first column:'
A_1_1 = int(raw_input())
print 'First row, second column:'
A_1_2 = int(raw_input())
print 'Second row, second column:'
A_2_1 = int(raw_input())
print 'Second row, second column:'
A_2_2 = int(raw_input())
A_1 = (A_1_1, A_1_2)
A_2 = (A_2_1, A_2_2)
matrix_2x2_define.A.A = A_1, A_2
print 'Matrix A is:'
#print '[ '+A_1_1+' '+A_1_2+' ]'
#print '[ '+A_2_1+' '+A_2_2+' ]'
print A_1
print A_2
def B(B):
print 'First row, first column:'
B_1_1 = int(raw_input())
print 'First row, second column:'
B_1_2 = int(raw_input())
print 'Second row, second column:'
B_2_1 = int(raw_input())
print 'Second row, second column:'
B_2_2 = int(raw_input())
B_1 = (B_1_1, B_1_2)
B_2 = (B_2_1, B_2_2)
matrix_2x2_define.B.B = B_1, B_2
print 'Matrix B is:'
#print '[ '+A_1_1+' '+A_1_2+' ]'
#print '[ '+A_2_1+' '+A_2_2+' ]'
print B_1
print B_2
matrix_2x2_define
matrix_2x2_define.A(A)
matrix_2x2_define.B(B)
print matrix_define_2x2_A.A
print matrix_define_2x2_B.B
print matrix_2x2_define.A.A
print matrix_2x2_define.B.B
raw_input
Here's the error:
Traceback (most recent call last):
File "C:/Documents and Settings/Student/My Documents/0000/Calculator/Matrix calculator.py", line 102, in <module>
matrix_2x2_define.A(A)
TypeError: unbound method A() must be called with matrix2x2_define instance as first argument (got int instance instead)_
Any help would be greatly appreciated.