Repeating Steps
Use a for loop to repeat code.
Use range to create a list of numbers
We often have to repeat steps in a process. If you are making a cake the recipe might say add an ingredient and then stir it 50 times or until the batter is smooth. You can probably handle stirring the batter 50 times, but what if you had to stir it 1,000 times? You might want a machine to do that.
A computer never gets tired. It can do the same thing over-and-over without slipping up. It can execute a program for as long as it has electricity. So, there must be a way to tell a computer to do things over-and-over. Computers know how to repeat steps in a program and the way they do this is often called a loop or iteration. Have you ever had an earworm? This is when a song gets stuck in your head and keeps repeating as if the song was set to loop (repeat after playing).
What is a List?
A list holds items in order, and they are often enclosed in [ and ] and can have values separated by commas, like [1,2,3,4,5,6,7,8,9,10]. You probably use lists all the time. People often make a list before they go shopping or a list of things to do. A list has an order and each list item has a position in the list, like the first item in a list or the last item in a list.
Concepts from computing
Accumulator Pattern - The accumulator pattern is a set of steps that processes a list of values. One example of an accumulator pattern is the code to sum a list of numbers.
Body of a Loop - The body of a loop is a statement or set of statements to be repeated in a loop.
Indention - Indention means that the text on the line has spaces at the beginning of the line so that the text doesn’t start right at the left boundary of the line. I
Iteration - Iteration is the ability to repeat a step or set of steps in a computer program. This is also called looping.
List - A list holds a sequence of items in order. An example of a list in Python is [1, 2, 3].
Loop - A loop tells the computer to repeat a statement or set of statements.
Body of a Loop - The body of a loop is a statement or set of statements to be repeated in a loop.
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.
Post a Comment
0Comments