Python Matrices, Modules & Exception Handling – Week 5 Lecture

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

flashcard set

Earn XP

Description and Tags

15 vocabulary flashcards covering matrix operations, module construction, geometry functions, and exception handling as presented in the Week 5 lecture notes.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

Matrix

A two-dimensional array (list of lists) in which elements are arranged in rows and columns.

2
New cards

Square Matrix

A matrix with the same number of rows and columns (e.g., 3 × 3).

3
New cards

print_matrix( )

Helper function that iterates through each row of a matrix and prints the elements joined by spaces.

4
New cards

Matrix Addition

Element-wise summing of two matrices of identical dimensions, producing a new matrix where each entry is the sum of corresponding entries.

5
New cards

add_matrices( )

User-defined Python function that adds two square matrices by looping through indices i, j and storing sums in a result matrix.

6
New cards

Matrix Multiplication

Operation that multiplies two matrices by taking the dot product of rows of the first matrix with columns of the second, producing a new matrix.

7
New cards

multiply_matrices( )

Custom Python function that performs square-matrix multiplication using triple-nested loops (i, j, k) to accumulate sum_product values.

8
New cards

Module (Python)

A file containing Python definitions and statements that can be imported and reused in other programs.

9
New cards

main

Special name set by Python; code under if name == 'main': runs only when the module is executed directly, not when imported.

10
New cards

math Module

Built-in Python library providing mathematical constants (e.g., pi) and functions such as sqrt().

11
New cards

circle_area( )

Geometry-module function that returns π × radius² using math.pi.

12
New cards

triangle_area( )

Function that computes a triangle’s area via Heron’s formula using the semi-perimeter s = (a + b + c)/2.

13
New cards

Exception Handling

Mechanism for catching and responding to runtime errors with try, except, else, and finally blocks.

14
New cards

try-except Block

Code structure that runs statements in try and executes except clauses if specified exceptions occur, preventing program crashes.

15
New cards

General-Purpose Exception (Exception)

Base class for all built-in, non-system-exit exceptions; catching it (except Exception as e) intercepts most runtime errors.