16,016,306 members

I have tried giving input for a 2X2 matrix.

But the output still is "Matrix not allowed" according to my code, whereas for this input it should just run well. Please let me know where I am going wrong.

**What I have tried:**

This is my code

0 1 0 x x 1 y x

But the output still is "Matrix not allowed" according to my code, whereas for this input it should just run well. Please let me know where I am going wrong.

This is my code

Python

import numpy as np import pandas as pd n=int(input('Give value of n size of the matrix : ')) arr=np.zeros([n,n]) df=pd.DataFrame(arr) print(df) rows = n col = n num=rows*col b=input('First character: ') d=input('Second charater: ') i=1 while i<=num: e=int(input('enter row no.:')) f=int(input('enter col no.:')) choice = input('Which character do you want to enter : ') if choice!=b and choice!=d: print('Enter correct charcters') choice = input('Which character do you want to enter : ') if df.iat[e,f]!=0: print('position is filled! give different coordinates') e=int(input('enter row no.:')) f=int(input('enter col no.:')) df.iat[e,f]=choice print(df) i+=1 for a in range(2,n+1): for j in range(0,n-a+1): if df.iat[j,j]==df.iat[j,j+a-1] and df.iat[j,j]==df.iat[j+a-1,j] and df.iat[j,j]==df.iat[j+a-1,j+a-1]: z=1 if z==1: print('matrix not allowed')

Comments

Richard MacCutchan
27-Mar-22 4:57am

The problem is with the final if statement. It only allow a matrix where the rows and columns match. So you need to modifiy that test for whatever rules you are trying to apply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900