Iteration Flashcards
What does indenting code mean?
Creating a new line of code and pressing tab to move the code to the write so this bit of code is in a loop/iteration.
In a for loop what does the third number do?
The third number tells the program in what intervals it should count, it is known as the step.
If you typed ‘for i in range(3)’ what would be the output and what is missing from this code?
Nothing would be outputted but the variable i would count from 0 to 2, the reason the code would not work is because there is no colon at the end.
Can you have a loop in a loop?
Yes
What should you always do at the beginning of a piece of code?
Initialize the variable / give them a starting point.
What is sudocode?
It is a type of written python that is literal so if you wrote ‘for i from 1 to 5’ you wouldn’t need the brackets etc.
Can you do a for loop with strings so like in this piece of sudocode ‘for s in myStr’
Yes, check iteration workbook page 11 if this is confusing.
What does ‘end = ‘ ‘’ do?
It switches the end of a line, for example in an iteration to just print a space, as it normally moves down a line.
What two types of loop exist?
A for loop and a while loop.
What are some real world applications of a while loop?
Passwords, PINs or Validation/Adresses
What does += do?
It takes a varibale and then adds the number displayed after the += to the original value.
Does -= or x= work?
Yes
What does the exclamation mark do in this piece of code? ‘while name!= ‘x’:’
It means while x doesn’t equal name.
What are the three main parts of an iteration program as well as initialising all variables at the begionning?
Sequence, Selection and Iteration
What is a for loop?
A loop that will repeat a given number of times, specified in the loop.