0% found this document useful (0 votes)
86 views6 pages

U7 - Worksheet 3 Iteration

The document contains examples and tasks related to programming concepts like sequences, selection, iteration, and writing pseudocode algorithms. The tasks involve writing pseudocode to analyze sample code, count scores over 100, calculate averages, draw shapes with a turtle, and validate email addresses.

Uploaded by

jamespalmer192
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views6 pages

U7 - Worksheet 3 Iteration

The document contains examples and tasks related to programming concepts like sequences, selection, iteration, and writing pseudocode algorithms. The tasks involve writing pseudocode to analyze sample code, count scores over 100, calculate averages, draw shapes with a turtle, and validate email addresses.

Uploaded by

jamespalmer192
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

J277 – Unit 7 Programming

Worksheet 3 Iteration (Date: __ / __ / __ )


Task 1
1. Examine the pseudocode program given below.
(a) Which lines show an example of a sequence?
1-2 4-6 10-11 14-16

(b) Which lines show an example of the ‘Selection’ programming construct?


9-12

(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 print("This program prints selected numbers in a given range")


2 anotherGo = "Y"
3 while anotherGo == "Y"
4 lowNumber = int(input("Please enter first number in your
chosen range: "))
5 highNumber = int(input("Please enter last number in your
chosen range: "))
6 totalNum = 0
7
8 for i = lowNumber to highNumber
9 if i MOD 5 != 0 and i MOD 7 != 0
10 print(i)
11 totalNum = totalNum + 1
12 endif
13 next i
14 print(totalNum)
15 answer = input("Another go? (Y or N)")
16 anotherGo = answer.upper()
17 endwhile

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):"))

while score != -1:


if score > 100:
totalCount += 1
score = int(input("Enter the next numeric score:"))

print(f"Number of scores over 100: {totalCount}")

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

#allow for user entering no scores

If numscore == 0:

2
J277 – Unit 7 Programming

Print(“\nNo scores entered – program ended”)


Else:
Averagescore = totalscore/numscore
Print(“\nAverage scpre: “, averagescore)

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

(Each square in the drawing is 10cm by 10cm.)

(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:

 ask a user to enter their email address

 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

 a do…unit loop must be used as part of the program

You might also like