List of Exercises
Exercise 1.1: Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.2: Volume of a Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.3: Area and Circumference of a Circle . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.4: Volumes of Three Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.5: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 1.6: Formatted Print to Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 2.1: Interactive Computing of Volume . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.2: Interactive Computing of Circumference and Area . . . . . . . . . . . 56
Exercise 2.3: Update Variable at Command Prompt . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.4: Multiple Statements on One Line . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.5: Boolean Expression—Even or Odd Number? . . . . . . . . . . . . . . . . 57
Exercise 2.6: Plotting Array Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.7: Switching Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.8: Drawing Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exercise 3.1: A for Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.2: The range Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.3: A while Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.4: while Loop Instead of for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.5: Compare Integers a and b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.6: Area of Rectangle Versus Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.7: Frequency of Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.8: Game 21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.9: Simple Search: Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.10: Sort Array with Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.11: Compute π . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 4.1: Errors with Colon, Indent, etc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.2: Reading Code 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.3: Reading Code 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.4: Functions for Circumference and Area of a Circle . . . . . . . . . . . . 98
Exercise 4.5: Function for Adding Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.6: Function for Area of a Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.7: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.8: When Does Python Check Function Syntax? . . . . . . . . . . . . . . . . 99
Exercise 4.9: Find Crossing Points of Two Graphs . . . . . . . . . . . . . . . . . . . . . . . 99
xxi
Exercise 1.1: Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.2: Volume of a Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.3: Area and Circumference of a Circle . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.4: Volumes of Three Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.5: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 1.6: Formatted Print to Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 2.1: Interactive Computing of Volume . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.2: Interactive Computing of Circumference and Area . . . . . . . . . . . 56
Exercise 2.3: Update Variable at Command Prompt . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.4: Multiple Statements on One Line . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.5: Boolean Expression—Even or Odd Number? . . . . . . . . . . . . . . . . 57
Exercise 2.6: Plotting Array Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.7: Switching Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.8: Drawing Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exercise 3.1: A for Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.2: The range Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.3: A while Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.4: while Loop Instead of for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.5: Compare Integers a and b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.6: Area of Rectangle Versus Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.7: Frequency of Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.8: Game 21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.9: Simple Search: Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.10: Sort Array with Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.11: Compute π . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 4.1: Errors with Colon, Indent, etc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.2: Reading Code 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.3: Reading Code 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.4: Functions for Circumference and Area of a Circle . . . . . . . . . . . . 98
Exercise 4.5: Function for Adding Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.6: Function for Area of a Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.7: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.8: When Does Python Check Function Syntax? . . . . . . . . . . . . . . . . 99
Exercise 4.9: Find Crossing Points of Two Graphs . . . . . . . . . . . . . . . . . . . . . . . 99
xxi
