Iteration Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What does indenting code mean?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In a for loop what does the third number do?

A

The third number tells the program in what intervals it should count, it is known as the step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If you typed ‘for i in range(3)’ what would be the output and what is missing from this code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you have a loop in a loop?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What should you always do at the beginning of a piece of code?

A

Initialize the variable / give them a starting point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is sudocode?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you do a for loop with strings so like in this piece of sudocode ‘for s in myStr’

A

Yes, check iteration workbook page 11 if this is confusing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘end = ‘ ‘’ do?

A

It switches the end of a line, for example in an iteration to just print a space, as it normally moves down a line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What two types of loop exist?

A

A for loop and a while loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some real world applications of a while loop?

A

Passwords, PINs or Validation/Adresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does += do?

A

It takes a varibale and then adds the number displayed after the += to the original value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Does -= or x= work?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the exclamation mark do in this piece of code? ‘while name!= ‘x’:’

A

It means while x doesn’t equal name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three main parts of an iteration program as well as initialising all variables at the begionning?

A

Sequence, Selection and Iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a for loop?

A

A loop that will repeat a given number of times, specified in the loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a while loop?

A

A loop that will repeat indefinitely until criteria is met or something becomes true, then the program will move on to the next part.

16
Q

When writing a code, when should you use a while loop and when should you use a for loop?

A

Use a while loop when you want something to change, like a variable value due to the loop and it will keep changing, if told to do so, until it meets the criteria. Use a for loop if you just want something to repeat a given number of times.

17
Q

What is a nested iteration?

A

A loop inside of another loop, they can be different types of loop.

18
Q

What is the main purpose of loops?

A

To save time and effort, making our programs more efficient.

19
Q

Explain how a nested loop works.

A

Everytime the outer loop completes one full loop the inner loop has completed mulitiple, as many as stated in the program.

20
Q

What is an example of using a nested loop to create a code?

A

I used a nested iteration to make a code that had to write multiple rows of code. I used a nested iteration as it allowed the inner loop to repeat the text on the row, whilst the outer loop mover rows.