To solve this question you can use the following algorithm:
import numpy as np
m = int(input('Digite o número de linhas: '))
n = int(input('Digite o número de colunas: '))
lista = list()
for i in range(1, m + 1):
linha = list()
for j in range(1, n + 1):
while True:
try:
v = int(input(f'Digite o {j}º valor da {i}ª linha: '))
break
except ValueError:
print('\033[31mValor INVÁLIDO! Digite apenas valores inteiros!\033[m')
linha.append(v)
lista.append(linha)
d_p = np.std(lista)
print(f'\033[32mO desvio padrão é:\n{d_p:.2f}\033[m')
Note that even if you enter integer values, the result of the standard deviation will always be a floating point number.
See here the definition of standard deviation.
Note that in this algorithm I imported the numpy library, which I had already installed in my IDE.
When we run this algorithm we are asked the number of rows and columns.
Why is that?
Because with row number and columns I can assemble a structure of an array, more precisely a list of lists.
Also note that the nesting of blocks for
assemble a list of lists containing all values that will be passed.
Subsequently the method std
library numpy
calculates the standard deviation of all values of all lists.
Now, if you just want to calculate the summing up of all standard deviations from the lists, you can use the following algorithm:
import numpy as np
n = int(input('Quantas lista desejas calcular? '))
soma = 0
for c in range(1, n + 1):
lista = list(map(int, input(f'Digite todos os valores da {c}º lista: ').split()))
d_p = np.std(lista)
soma += d_p
print(f'\033[32mA soma dos desvios padrões são: {soma:.2f}\033[m')
Note that when we run this second algorithm we receive the following message:Quantas listas desejas calcular
. At this time we must inform the number of lists. Then we received the following message: Digite todos os valores da 1ª lista
. Right now we must type all the values in the same line, separated by a single space and then press enter.
Later we must enter the values of the other lists.
For each list the algorithm will calculate its desvio padrão
and accumulate its values in the counting variable soma
. then the value will be displayed.
What are the types of values you want to insert in this list? integers or real?
– Solkarped
probably whole.
– Daniel Brito