(ProgWerk) Python Fundamentals


Figure 1

Value of 65.0 with weight_kg label stuck on it

Figure 2

Value of 65.0 with weight_kg label stuck on it, and value of 143.0 with weight_lb label stuck on it

Figure 3

Value of 100.0 with label weight_kg stuck on it, and value of 143.0 with label weight_lbstuck on it

(ProgWerk) Storing Multiple Values in Lists


Figure 1

veg is represented as a shelf full of produce. There are three rows of vegetableson the shelf, and each row contains three baskets of vegetables. We can labeleach basket according to the type of vegetable it contains, so the top rowcontains (from left to right) lettuce, lettuce, and peppers.

Figure 2

veg is now shown as a list of three rows, with veg[0] representing the top row ofthree baskets, veg[1] representing the second row, and veg[2] representing the bottom row.

Figure 3

To reference a specific basket on a specific shelf, you use two indexes. The first index represents the row (from top to bottom) and the second index represents the specific basket (from left to right). veg is now shown as a two-dimensional grid, with each basket labeled according toits index in the nested list. The first index is the row number and the secondindex is the basket number, so veg[1][3] represents the basket on the far rightside of the second row (basket 4 on row 2): zucchini


(ProgWerk) Repeating Actions with Loops


Figure 1

Line graphs showing average, maximum and minimum inflammation across all patients over a 40-dayperiod.

Figure 2

Loop variable 'num' being assigned the value of each element in the list odds in turn andthen being printed

(ProgWerk) Making Choices


Figure 1

A flowchart diagram of the if-else construct that tests if variable num is greater than 100

Figure 2

C gets printed because the first two conditions, 4 > 5 and 4 == 5, are not true, but 4 < 5 is true. In this case only one of these conditions can be true for at a time, but in other scenarios multiple elif conditions could be met. In these scenarios only the action associated with the first true elif condition will occur, starting from the top of the conditional section. A flowchart diagram of a conditional section with multiple elif conditions and some possible outcomes. This contrasts with the case of multiple if statements, where every action can occur as long as their condition is met. A flowchart diagram of a conditional section with multiple if statements and some possible outcomes.


(ProgWerk) Creating Functions


Figure 1

Labeled parts of a Python function definition

(ProgWerk) Errors and Exceptions


(ProgWerk) Defensive Programming


Figure 1

Graph showing three number lines and, at the bottom, the interval that they overlap.

(ProgWerk) Debugging


(ProgWerk) Command-Line Programs