0% found this document useful (0 votes)
2 views

Unit 6 - Grade 8 - Revision Paper

The document covers key programming concepts for Grade 8, including decomposition, count-controlled loops (FOR loops), data types, and arrays. It provides definitions, examples, and syntax for using loops in Python, as well as details about arrays and their fixed nature. The document emphasizes the importance of correct naming conventions in programming.

Uploaded by

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

Unit 6 - Grade 8 - Revision Paper

The document covers key programming concepts for Grade 8, including decomposition, count-controlled loops (FOR loops), data types, and arrays. It provides definitions, examples, and syntax for using loops in Python, as well as details about arrays and their fixed nature. The document emphasizes the importance of correct naming conventions in programming.

Uploaded by

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

Revision Paper – Unit 6

Grade 8 – Programming and Computational Thinking 2

Definition of Terms:

Decomposition – means breaking a complex problem down into smaller, more


manageable parts.

Practically all the Repetitive and Simple task in our daily lives can be decompose into
smaller activities.

Count-Controlled Loop – The FOR Loop – these are essential in programming when you
need to repeat a block of code a predetermined number of times.

Data Types and Uses:

Data Type Example


String Any textual characters, such as “Hello World” or “VSC0321”
Integer Any signed whole number, such as 24 or -10
Real Any signed number with a decimal point, such as 6.98 or -0.45
Boolean Either a Yes/No, True/False, On/OZ

Comparison Symbols

Kindly take note of the following comparison symbols being used in the Selection (IF-
ELSE and IF-ELIF-ELSE)
Count-Controlled Loop (The FOR Loops)

Syntax:
Python
for variable in range(start, stop, step):
# Code to be executed repeatedly

Examples:
1. Printing Numbers 0 to 4:
Python
for i in range(5):
print(i)

• Explanation: The loop iterates from 0 to 4 (5 is exclusive).


• Output:
• 0
• 1
• 2
• 3
• 4

2. Printing Numbers 1 to 10:


Python
for i in range(1, 11):
print(i)

• Explanation: The loop starts at 1 and goes up to 10 (11 is exclusive).


• Output:
• 1
• 2
• 3
• 4
• 5
• 6
• 7
• 8
• 9
• 10

3. Printing Even Numbers from 2 to 10:


Python
for i in range(2, 11, 2):
print(i)

• Explanation: The loop starts at 2, goes up to 10, and increments by 2.


• Output:
• 2
• 4
• 6
• 8
• 10

4. Printing a String Multiple Times:


Python
for _ in range(3):
print("Hello, Python!")

• Explanation: The loop runs 3 times, printing the string each time. _ is used
when the loop variable isn't needed.
• Output:
• Hello, Python!
• Hello, Python!
• Hello, Python!

5. Calculating the Sum of Numbers from 1 to 5:


Python
total = 0
for i in range(1, 6):
total += i
print("Sum:", total)

• Explanation: The loop adds each number from 1 to 5 to the total variable.
• Output:
• Sum: 15

Arrays and List

An array holds multiple items under one name.


An array is a static data structure.
An array is fixed in size and can only contain data of the same type.
The contents can be changed, but items cannot be added or deleted.
The structure must remain fixed.
It will display MONDAY. The First element of an array is addressed at 0 as shown in the
table above. You start counting the elements of an array at days[0], days[1].....

The answer will be “TUESDAY”


The answer will be “Friday”

The answer will be an ERROR since there is no 7th element of the Array.

BE CAREFUL WITH THE NAMES OF THE ARRAY:

As you can see in the array the name of the array is days, so if you use the name day (no
s), there will be an error.

You might also like