0% found this document useful (0 votes)
44 views2 pages

Practical 4

Uploaded by

sameehmuhammed30
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)
44 views2 pages

Practical 4

Uploaded by

sameehmuhammed30
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/ 2

Pakistan International School Jeddah - English Section

Y8-Computing
Unit 9.1: Presenting choices: Combining Constructs

Practical Task 4 – For loop Total Marks: 10

Name: Student ID: Y8 -____

All programming languages have 3 elements in common that give us the power to implement
solutions to extremely complex problems.
These 3 elements are:
 Sequence
 Selection
 Iteration
let’s describe these elements:

1. Sequence: This means that the computer will run your code in order, one line at a time
from the top to the bottom of your program. It will start at line 1, then execute line 2 then
line 3 and so on till it reaches the last line of your program.
2. Selection: Sometimes you only want some lines of code to be run only if a condition is met,
otherwise you want the computer to ignore these lines and jump over them. This is
achieved using IF statements. e.g., If a condition is met then lines 4, 5, 6 are executed
otherwise the computer jumps to line 7 without even looking at line 4,5 and 6.
3. Iteration: Sometimes you want the computer to execute the same lines of code several
times. This is done using a loop. There are three types of loops: For loops, while loops and
repeat until loops. That’s handy as it enables you not to have to copy the same lines of code
many times.

For Loop:
A count-controlled loop is where a series of program instructions is repeated a set number of
times. (note: loop variable always starts at 0)
For example, Variable name In is used to separate the variable from the
number of times the loop will run
for i in range (5):

Tells the computer that it will be the number of times the loop will run
running a for loop

Y8-Computing 2023-24 Practical 4 Page 1 of 2


1. Open the IDLE python from your computer.

2. Write a program that repeats Hello world 8 times using for loop.

3. Save the program in python folder with name task p4a.py

Evidence 1: Take the screenshot of python shell & script mode both and paste it in your
evidence file.

4. Write a program that will display square of a number 2 times.

5. Save the program in python folder with name task p4b.py

Evidence 2: Take the screenshot of python shell & script mode both and paste it in your
evidence file.

6. Write pseudocode of both the programs in your manuscript.

7. Write a program that will give output A, then B, then it will alternate C’s and D’s

five times and then finish with the letter E once.

8. Save the program in python folder with name task p4c.py

9. Modify the above program to print five C’s followed by five D’s, instead of alternating C’s and D’s to
produce the following output.

Evidence 3: Take the screenshot of python shell & script mode both and paste it
in your evidence file.

--------------------------------------------

Y8-Computing 2023-24 Practical 4 Page 2 of 2

You might also like