-1
My goal in this algorithm is to find how many times the number 2 appears within an 8x3 matrix.
My result so far is like this:
from collections import Counter
import time
import numpy as np
m = int(input('Quantas linas? '))
n = int(input('Quantas colunas? '))
input("Será aceito somente números entre -20 e 10.\n ... \nPrecione a tecla ENTER para continuar!\n")
time.sleep(2)
matrizA = list()
for c in range(1, m + 1):
linha = list()
for i in range(1, n + 1):
while True:
try:
valor = int(input(f'Digite o {i}º elemento da {c}ª linha: '))
break
except ValueError:
print('\033[31mValor INVÁLIDO! Digite apenas valores inteiros!\033[m')
linha.append(valor)
matrizA.append(linha)
matriz = np.array(matrizA)
print(f'\033[32mA matriz gerada é:\n{matriz}\033[m')
c = Counter(matrizA)
print(c[2])
I managed to make the matrix and tried to use the import Counter
to return the result of the repetition of the number 2 inside the matrix. However the result did not come out as I wanted.