1. The three programming constructs are: (3 marks)
2. These two loops produce identical outputs. Try it yourself!
3. Name two types of loops (2 mark)
4. The programmer would like the output of the code to be as shown below. The numbers should start at 1 and go up to 5. What needs to be added to the code to make this happen?
5. Iteration is the term given to the ________ of a block of statements (code) within a computer program. Basically, think loops!
6. Read the excerpt below and fill in the blanks. Remember the terms 'condition controlled' and 'count controlled'.
7. What in the following code needs to be changed for the program to ask the user to enter their password 5 times?
8. The programmer wants to draw another black circle after the last purple circle. What code does he need to add?
9. In the code above point out which line, if at all, is using iteration.
10. The following code produces an output of: 2,3,4,5,6,7,8,9. What needs to change so that it produces an output of 1 to 10?
11. The following code is repeating the creation of squares, each inside the other, but it stops at count = 50. What do you need to change to make it go all the way up to 100 and complete the pattern?
12. A while loop is different from a for loop in that it is ____________ controlled rather than _______ controlled.
13. The first for loop has a specified starting and stopping condition. Which statement is true of the while loop? (Try it yourself if you're unsure)
#For loop - start value is 1, and stopping condition is 11
for score in range(1,11):
print(score)
#the above loop prints 1,2,3,4,5,6,7,8,9,10
#While loop
score=0
while score <11:
print(score)
The loop goes on forever. The score remains 0.
All the statements listed here are correct
It has a starting value of 0. It also has a stopping condition of 11.
The score starts at 0 and remains 0 for infinity (forever) because there is no incrementation
14. In the code below, what needs to be added/changed to the while loop in order to make it print the numbers 1,2,3,4,5,6,7,8,9,10.
15. In certain situations a while loop may never run. What needs to change to enable this while loop to run? Select the statement that is entirely correct.
16. Why will the following while loop fail to run? Becaue the condition on line 2 is __________.
17. The following code will not run! What one thing do you need to change in order for it to work properly?
18. Have a look at lines 8 and 9. How would you describe what has been coded here?
19. On line 2 what is the != operator?