Okay, I think I understand what you need, so I’m going to really focus on the problem: a loop of repetition that reads m
lines in the format a b c d ...
, Separate this line into values and convert 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 for
is to ensure that the m
lines. THE while
ensures that the input will always read the expected number of columns, thus preventing the user to enter a different value - if the matrix has 3 columns, the input 1 2
will be invalid. Read input, separate values with split
in white spaces and converted to float with the function map
.
That is, your code was on the right track, but must have been wrapped up with 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 list
to convert it to a list.
It was not very clear what you need to do. You can try to explain better?
– Woss
I have to make a simplex and I will have several entries and a matrix A, this matrix would have a bit n of columns and m of rows. the input will be
1 2 3 4
, for example. I need to transform this to float. It seems to me that when you enter a line like this in input() it takes like a string.– Guilherme Ferreira