Active4 years, 8 months ago
badp8,79133 gold badges5151 silver badges8080 bronze badges
Bunny Rabbit
Asa cum stim, instructiunea WHILE cicleaza conform rezultatului unei conditii. In acest caz, se incearca citirea din fisier a valorii X. Daca instructiunea se executa cu succes, se returneaza valoarea 1 (ADEVARAT) si putem prelucra valoarea citita. Daca citirea din fisier nu se poate realiza, se va returna valoarea 0 (FALS).
Bunny Rabbit3,9431515 gold badges5050 silver badges9494 bronze badges
4 Answers
Community♦
György AndrasekGyörgy Andrasek5,82722 gold badges3939 silver badges7070 bronze badges
Python doesn't have matrices. You can use a list of lists or NumPy
Ed.Ed.
If you are not going to use the NumPy library, you can use the nested list. This is code to implement the dynamic nested list (2-dimensional lists).
Let
r
is the number of rowsAny time you can append a row using
Above, you have to enter the matrix row-wise. To insert a column:
To print the matrix:
Jawa2,25066 gold badges3131 silver badges3535 bronze badges
Gautam SethGautam Seth
Using tuples instead of lists makes it marginally harder to change the data structure in unwanted ways.
If you are going to do extensive use of those, you are best off wrapping a true number array in a class, so you can define methods and properties on them. (Or, you could NumPy, SciPy, ... if you are going to do your processing with those libraries.)
badpbadp8,79133 gold badges5151 silver badges8080 bronze badges