Module 3 chapter 3
Not equal to in programming
!=
Less than in programming
<
Less than or equal to in programming
<=
Equal to in programming
==
Greater than in programming
>
Greater than or equal to in programming
>=
Backward Method
Ask yourself what must be true for the loop to end. Then reverse that condition to decide what will be true while the loop is repeating. This backward method of thinking takes some getting used to, but it will help you write perfect loops before long!
As soon as the condition becomes false what will the loop do?
End
What does python use as Boolean logic to determine whether the condition is true or false?
Python uses what's known as Boolean logic to determine whether the condition is true or false.
Common factors of for and while loops:
Repeat a block of code Will stop once the condition is false
for loops
Repeat for a set range of values. The loop variable is given a start value. Best used when you know the exact number of repetitions needed.
while loops
Repeats while a Boolean condition is true The loop variable is assigned a value before the loop Best used when you do not know the exact number of repetitions needed
What is the key?
The key is paying attention to detail and logic.
There are some important syntax points to be aware of when writing a while loop:
The statement begins with the keyword while. The test condition goes inside the parentheses. The statement ends with a colon. The code in the body of the loop gets indented.
What are Programmer-Defined Functions?
They're basically long lists of instructions that a programmer has broken into chunks of code.
Boolean conditions for while loops can be what?
Thinking in Boolean conditions for while loops can be pretty tricky at first.
What's a while loop?
This command waits for an event to happen. It tells Python to repeat the action while a certain condition is true. Use this loop when you don't know the exact number of times you need your code to run.
What's a for loop?
This structure is commonly used to count through a range. It tells Python to repeat the action for a certain number of iterations. Use this loop when you know the exact number of times your code should run
What will you need to use to make the loop understand the conditions necessary for it to run?
To make your while loop understand the conditions necessary for it to run, you will need to use one of the six relational operators.
Will the loop repeats the action as long a the condition provided is?
True
What do we use while loops for?
We use while loops to repeat actions when we cannot find the number of necessary iterations easily, or when there's no way of knowing the specific number.
A while loop needs to know two main things what are they?
What action to do , The conditions for doing this action
Is it possible to write infinite loops?
Yes! These go on forever.
What is an example of a for loop?
for x in range(0, 1, 10):
What opens each of your programs?
the main() function
How many kinds of loops are there and what are they?
two, they are for loops and while loops
for loops and while loops are similar in that they are both loops, but they differ in?
why and how you use them.
What is an example of a while loop?
x = 0 while(x < 10): x = x + 1