U7 - Worksheet 3 Iteration
U7 - Worksheet 3 Iteration
(c) There are two examples of iteration statements in the program. On which lines do each
of the ‘Iteration’ programming construct begin and end?
3-17 and 8-13
(d) If the user enters 1 and 10 for the lowNumber and highNumber, what will be printed out
at line 14?
7
1
J277 – Unit 7 Programming
Task 2
1. Write a pseudocode algorithm which inputs numeric scores and outputs how many of them
are over 100. The end of the data is signalled by a user input of -1.
totalCount = 0
score = int(input("Enter a numeric score (-1 to end):"))
2. Write a pseudocode algorithm which inputs numeric scores and outputs the average score.
The end of the data is signalled by a user input of -1.
Totalscore= 0
Numscore= 0
Morescore = true
While morescores
Score = int(input(“Enter the next score, -1 to end: “))
If score != -1
Numscore = numscore + 1
Totalscore = totalscore + score
Else
Morescores = False
If numscore == 0:
2
J277 – Unit 7 Programming
3
J277 – Unit 7 Programming
Task 3
A floor turtle uses these instructions.
Instruction Meaning
forward(n) Move n cm forward
backward(n) Move n cm backwards
left(d) Turn left d degrees
right(d) Turn right d degrees
penup() Raise the pen
pendown() Lower the pen
(a) Complete the set of instructions to draw the shape shown below in bold lines, starting
at the point markedhg. X.
X
pendown()
for i = 1 to 4
4
J277 – Unit 7 Programming
(b) Complete the set of instructions to draw the shape shown below in bold lines, starting
at the point marked X.
X
pendown()
for i = 1 to 3
for j = 1 to 4
(c) Complete the set of instructions to draw the shape shown above in bold lines, starting
at the point marked X.
pendown()
distance = 10
for i = 1 to 7
endfor
5
J277 – Unit 7 Programming
Task 4
An email address must contain an ‘@’ symbol. Write a program in pseudocode that will:
if they enter an email address without an @ symbol it will ask them to enter it again
to check if the email address contains an @ symbol, a for loop should be used to check
each character entered