6: Conditionals Part 1
- Page ID
- 86198
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
In this chapter, we’ll use functions and a new feature—conditional statements—to search for Pythagorean triples. A Pythagorean triple is a set of integers, like 3, 4, and 5, that are the lengths of the sides of a right triangle. Mathematically, it’s a set of integers \(a\), \(b\), and \(c\) such that \(a^2 + b^2 = c^2\). This example will also demonstrate the incremental development process we talked about in Chapter 3.
- 6.2: if Statement
- Use of the basic "it" logic block
- 6.3: if, else, elseif
- if, else, elseif, end examples
- 6.4: Incremental Development
- Outlines the steps for creating and testing a program.
- 6.5: Logical Functions
- Logical functions and operations. This is a modified version Of Allen Downey's section. It has been modified to use parentheses to remove ambiguity in the logic.
- 6.6: Nested for Loops
- nested loops
- 6.7: Putting It Together
- Now instead of displaying all of the triples, we’ll add an if statement and display only Pythagorean triples
- 6.8: Encapsulation and Generalization
- encapsulation: wrapping the code in a function
- 6.9: Adding a continue Statement
- continue short circuits a for loop
- 6.11: Chapter Review
- Chapter review
- 6.12: Chapter 6 if-logic videos English and Espanol
- Chapter 6 videos English and Espanol