Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make a function read a row and a column with only zeros without using libraries

I’m new to programming in general… I have to check all the rows and columns of an matrix and in case any of them are complete with zeros, return a True value. I made this code in a silly attempt but it doesn’t work for the purpose of the question itself. The matrix will always be a square and a list of lists.

def determinanteEhNulo(matriz):
  contador = 0
  
  for i in matriz:
    for j in range(len(matriz)):
      if i[j] == 0:
        contador += 1

  if contador >= int(len(matriz)):
    return True
  return False

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This seems to do what you need.

def determinanteEhNulo(matriz):
    for i in matriz:
        if all(x==0 for x in i):
            return True
    for i in zip(*matriz):
        if all(x==0 for x in i):
            return True
    return False
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading