Today in the library, I continued reviewing Python conditionals and watched part of Professor Qiu Weisheng's linear algebra course. I am still identifying the basic ideas in both subjects: Python makes it easy to stumble over punctuation and indentation, while the first algebra lesson introduced many new terms in quick succession.

f, colons, and indentation
The f prefix of a formatted string belongs outside the quotation marks and immediately before the opening quote, as in f"{number} is an integer". If f is placed inside the quotes, it becomes an ordinary character and Python will not substitute the variable inside the braces.
A colon is required after if, elif, and else. I also need a more precise version of the instruction that elif and else should be “flush left”: they should have the same indentation as the if to which they belong. They do not always begin at the leftmost edge of the file. The statements inside a branch are indented one level further.
This leap-year test contains an outer if and an inner if—elif—else chain:
year = int(input("Enter a year: "))
if year % 4 == 0:
if year % 100 != 0:
print(f"{year} is a leap year")
elif year % 400 == 0:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
else:
print(f"{year} is not a leap year")
The inner elif and else align with the inner if; the final else aligns with the outer if. Once conditionals are nested, indentation is part of the program's structure rather than merely a visual preference.

pass does not skip the rest of the program
pass is a null statement that performs no operation. Python does not allow a suite to be completely empty, so pass can serve as a placeholder when the branch has not yet been implemented.
if year > 2026:
pass
print("The program continues")
Nothing happens when execution reaches pass; control simply continues with the following statement. It is different from continue, break, and return: it neither advances directly to the next loop iteration, exits a loop, nor ends a function.
From an n-variable system to a matrix
I also watched the first lesson of Professor Qiu Weisheng's linear algebra course. It moved from n-variable linear systems to matrices, vector spaces, and the possible solution sets. The concepts arrived densely, and I have not connected them properly yet. For now, the dimensions of a matrix give me one line to hold on to.

If a linear system contains s equations and n unknowns, its coefficients form an s × n matrix. The s rows correspond to the equations, while the n columns correspond to the unknowns. A 4 × 4 matrix therefore has four rows and four columns; when it is a coefficient matrix, it represents four equations in four unknowns.
Writing the unknowns as a column vector x and the constants on the right-hand side as a column vector b compresses the system into Ax = b. Appending the constant column to the coefficient matrix produces the augmented matrix [A | b], whose dimensions are s × (n + 1). In this setting, a matrix is not merely a table of numbers. It is a compact way to record the whole system.
The lecture also connected n-variable systems with n-dimensional vector spaces. At this point, I can only record the first link: a solution made from n unknowns can be written as an n-dimensional column vector. How that develops into solution spaces and linear dependence still requires more of the course.

Today's difficulties were Python's indentation levels and the relationships among the algebraic ideas. Next time, I can do one concrete task for each: rewrite a nested conditional from memory, then construct the coefficient matrix of a system with three equations and four unknowns to check that rows correspond to equations and columns to unknowns.
Enough for today.
Comments
0 comments