SIZ TUTORIAL - HOW YOU CAN MAKE A MATRIX CALCULATOR USING PYTHON LANGUAGE WITHOUT USING NUMPY LIBRARY
20% OF THE PAYOUT TO @SIZ-OFFICIAL
![image.png](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmcinZgNTHn73Wq8RRFrUUduDHSg48rrhgD16GNnmrGUAm/image.png)
source
Hello everyone ✌️
It's me again sharing a python tutorial. In this tutorial, you would learn how to make a matrix calculator. This calculator is not made with the help of any library. Usually, we use the NumPy library in this calculator but this program is all made by logic. If you know python language you would understand all very easily.
CODE FOR INPUT:
In the input code, we will make a print statement of od displaying the options. and an input statement where the rows and column of the matrix would be asked. A while loop is being set which is an infinite loop. Then if the person chooses option 5 which is exit then it would break the loop and the user would be outta the program. Then we wrote the empty lists for the input.
print('*****WELCOME TO: [THE MATRIX CALCULATOR]*****')
a=int(input('Enter the number of rows/columns for the square matrix:'))
while True:
print('''OPERATIONS MENU:
1.Addition
2.Subtraction
3.Multiplication
4.Transpose of Matrices
5.Exit''')
d=int(input('Enter your option number: '))
if d==5:
break
x=[]
y=[]
CODE FOR THE INPUT OF MATRIX 1:
for i in range(1,a+1):
print('Enter the values for matrix 1 row',i,'separated by commas:',end='')
mt1=input()
r=mt1.split(',')
if len(r)==a:
for j in range(len(r)):
r[j]=int(r[j])
x.append(r)
elif len(r)!=a:
print('please enter the same number of columns as number of rows')
break
CODE FOR THE INPUT OF MATRIX 2:
for k in range(1,a+1):
if len(r)!=a:
break
else:
print('Enter the values for matrix 2 row',k,'separated by commas:',end='')
mt2=input()
s=mt2.split(',')
if len(s)==a:
for m in range(len(s)):
s[m]=int(s[m])
y.append(s)
else:
print('please enter the same number of columns as number of rows')
break
BREAKING THE WHILE LOOP IF ANY OF THE ROWS AND COLUMNS OF PROVIDED MATRICES ARE UNEQUAL:
if len(r)!=a or len(s)!=a:
break
CODE FOR OUTPUT OF MATRIX 1 IN MATRIX FORMAT:
print('Matrix 1:')
for b in x:
for c in b:
print(c,end=' ')
print('')
CODE FOR OUTPUT OF MATRIX 2 IN MATRIX FORMAT:
print('Matrix 2:')
for bb in y:
for cc in bb:
print(cc, end=' ')
print('')
CODE FOR THE ADDITION OF MATRIX 1 AND MATRIX 2:
def add():
addmt = []
for ii in range(0, a):
l = []
for jj in range(0, a):
l.append(x[ii][jj] + y[ii][jj])
addmt.append(l)
CODE FOR OUTPUT OF RESULTANT MATRIX IN MATRIX FORMAT:
print('Addition of above matrices is:')
for m in addmt:
for mm in m:
print(mm, end=' ')
print('')
if d==1:
add()
print('**THANKS FOR USING:[THE MATRIX CALCULATOR]**')
CODE FOR THE SUBTRACTION OF MATRIX 1 AND MATRIX 2:
def sub():
submt = []
for kk in range(0, a):
p = []
for oo in range(0, a):
p.append(x[kk][oo] - y[kk][oo])
submt.append(p)
CODE FOR OUTPUT OF RESULTANT MATRIX IN MATRIX FORMAT:
print('Subtraction of above matrices is:')
for g in submt:
for gg in g:
print(gg, end=' ')
print('')
if d==2:
sub()
print('**THANKS FOR USING:[THE MATRIX CALCULATOR]**')
CODE FOR THE MULTIPLICATION OF MATRIX 1 AND MATRIX 2:
def multi():
print('Multiplication of above matrices is:')
prod = [[0 for row in range(len(x))] for col in range(len(y[0]))]
for z in range(len(x)):
for w in range(len(y[0])):
for q in range(len(y)):
prod[z][w] += (x[z][q] * y[q][w])
CODE FOR OUTPUT OF RESULTANT MATRIX IN MATRIX FORMAT:
for t in prod:
for tt in t:
print(tt, end=' ')
print('')
if d==3:
multi()
print('**THANKS FOR USING:[THE MATRIX CALCULATOR]**')
CODE FOR THE TRANSPOSE OF MATRIX 1 AND MATRIX 2:
def trans():
CODE FOR TRANSPOSE OF MATRIX 1:
result = [[0 for ee in range(len(x))] for dd in range(len(y[0]))]
for e in range(len(x)):
for d in range(len(x[0])):
result[d][e] = x[e][d]
CODE FOR OUTPUT OF TRANSPOSE OF MATRIX 1 IN MATRIX FORMAT:
print('Transpose of Matrix 1:')
for h in result:
for hh in h:
print(hh,end=' ')
print('')
CODE FOR TRANSPOSE OF MATRIX 2:
result = [[0 for ee in range(len(x))] for dd in range(len(y[0]))]
for i in range(len(y)):
for j in range(len(y[0])):
result[j][i] = y[i][j]
CODE FOR OUTPUT OF TRANSPOSE OF MATRIX 2 IN MATRIX FORMAT:
print('Transpose of Matrix 2:')
for h in result:
for hh in h:
print(hh, end=' ')
print('')
if d==4:
trans()
print('**THANKS FOR USING:[THE MATRIX CALCULATOR]**')
If you like python tutorials and projects. You would like my these posts as well.
![]() | Python program for beginners - Bakery CakeShake - 10% to @steem.skillshare |
---|---|
![]() | SIZ TUTORIAL - HOW TO MAKE TEXT TO SPEECH PROGRAM WITH PYTHON |
BEST REGARDS
VVARISHAYY
MashahAllah, Huge struggle and huge reward. Congratulations 🎉
Yaya :) hard work never goes in vain :)
Plz verify my achievement 1 please mam @vvarishayy
Please verify my achievement2
https://steemit.com/hive-172186/@haseebshoukat/achievement2-by-haseebshoukat-or-or-task-basic-security-on-steem-or-or
Fantastic,
Dear friend you make a very good post thanks for sharing a good information with us. And it is very difficult. And i am really appreciate your work because you have many great and fantastic skills which you share with us. My best wishes for you.
Remember me in your prayers.
Regards , Faran
Thank you.
Madam kindly verify my achievement 3
https://steemit.com/hive-172186/@saqibimran/achievement-3-task-content-etiquette-by-saqibimran
Dear @vvarishayy! I've been working in @steemit-pak for over a two month and have yet to receive any assistance. Please have a look at my articles. Please let me know if any changes are still required.Thanks
Hi
Comments on others post and set the beneficiaries. Surely you will be noticed. I'll visit your profile dw.
Please mam my 3 achievement has not been verified yet. Please check it. Thank you very much.
https://steemit.com/hive-172186/@kashif5088/3nt9nt-achievement3-content-etiquette-by-kashif5088
Check😞 please
https://steemit.com/hive-172186/@zaheer123/achievement1-my-introduction-zaheer123-08-09-2021
Nice post madam😊