Chapter 8 - Summary¶
Chapter 8 included the following concepts from computing.
- Body of a Loop - The body of a loop is a statement or set of statements to be repeated in a loop. The body of a loop is indicated in Python with indention.
- Counter - A counter is a variable that is used to count something in a program.
- Increment - Increment means to increase the value of a variable by 1.
- Infinite Loop - An infinite loop is one that never ends.
- Logical Expression - An logical expression is either true or false. An
example of a logical expression is
x < 3.
Summary of Python Keywords and Functions¶
- def - The
defkeyword is used to define a procedure or function in Python. The line must also end with a:and the body of the procedure or function must be indented 4 spaces. - for - A
forloop is a programming statement that tells the computer to repeat a statement or a set of statements. It is one type of loop. - print - The
printstatement in Python will print the value of the items passed to it. - range - The
rangefunction in Python returns a list of consecutive values. If the range function is passed one value it returns a list with the numbers from 0 up to and not including the passed number. For example,range(5)returns a list of[0, 1, 2, 3, 4]. If the range function is passed two numbers separated by a comma it returns a list including the first number and then up to but not including the second number. For example,range(1, 4)returns the list[1, 2, 3]. If it is passed three valuesrange(start, stop, step)it returns all the numbers fromstartto one less thanstopchanging bystep. For example,range(0, 10, 2)returns[0, 2, 4, 6, 8]. - while - A
whileloop is a programming statement that tells the computer to repeat a statement or a set of statements. It repeats the body of the loop while a logical expression is true.