Okay, I think I understand what you need, so I'll really focus on the problem: a loop that reads% with% rows, in m
format, separates this row into values and converts them to float , keeping such values in a list. For this, we do:
m = int(input("Quantas linhas? "))
n = int(input("Quantas colunas? "))
for i in range(m):
while True:
row = input()
values = row.split(' ')
if len(values) == n:
break
values = list(map(float, values))
print(values)
The a b c d ...
is to ensure that the for
lines are read. m
ensures that the entry always reads the expected number of columns, thus preventing the user from entering a different value - if the array has 3 columns, the while
entry is invalid. I read the input, separated the values with 1 2
in the blanks and converted to float with the function split
.
In other words, your code was on the right track, but you must have rolled over the returns of the function, remembering to assign the return to a variable. It is worth remembering that the return of map
is a generator, so I used map
to convert it to a list.