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

Ict Revision Coding

A computing system consists of hardware and software that processes data to perform tasks, including components like CPU, RAM, and storage. It operates through a flow of input, processing, output, and storage, utilizing logical operators and control structures such as loops and functions. Additionally, it covers programming concepts, data types, and the implications of artificial intelligence and ethical considerations in technology.

Uploaded by

amandacathleen11
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

Ict Revision Coding

A computing system consists of hardware and software that processes data to perform tasks, including components like CPU, RAM, and storage. It operates through a flow of input, processing, output, and storage, utilizing logical operators and control structures such as loops and functions. Additionally, it covers programming concepts, data types, and the implications of artificial intelligence and ethical considerations in technology.

Uploaded by

amandacathleen11
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/ 22

Computing Systems

What is a Computing System?

• Definition: A computing system is a combination of hardware and software that


processes data to perform tasks.

Key Components

• Hardware: The physical parts of a computer.

• CPU (Central Processing Unit): The brain of the computer that processes
instructions.

• RAM (Random Access Memory): Temporary memory that stores data for quick
access.

• Storage: Hard drives or SSDs that keep data long-term.

• Input Devices: Tools like keyboards and mice that let you enter data.

• Output Devices: Tools like monitors and printers that show results.

How It Works

• All computing systems follow this basic flow:

• Input → Processing (CPU) → Output → Storage.

Logical Operators

What Are Logical Operators?

• Logical Operators help make decisions in programming.

• AND: True if both conditions are true.

• OR: True if at least one condition is true.

• NOT: Changes true to false and vice versa.

Logic Gates

• Logic Gates are like switches that control how data flows.

• AND Gate: Outputs true only if both inputs are true.

• OR Gate: Outputs true if at least one input is true.

• NOT Gate: Outputs the opposite of the input.

Programming Concepts

What Are Algorithms and Programs?

• Algorithm: A step-by-step plan to solve a problem.

• Program: A set of instructions written in a programming language (like Python).


Control Structures

• Sequence: Steps are followed in order.

• Selection (If Statements): Chooses what to do based on conditions.

• Iteration (Loops): Repeats a set of instructions multiple times.

Variables

• Variable: A named space in memory to store data.

• Data Types:

• Integer: Whole numbers (e.g., 1, 2, 3).

• Float: Decimal numbers (e.g., 1.5, 2.7).

• String: Text (e.g., "Hello").

Example of a Simple Python Program

Artificial Intelligence (AI) and Machine Learning

• AI: Machines that can perform tasks that usually need human thinking.

• Machine Learning: A part of AI that helps computers learn from data.

• Examples: Used in things like facial recognition and recommendations on streaming


services.

Moral Issues in Technology

• Ethical Questions: Concerns about privacy, fairness, and the impact of technology on
jobs.

The elif Statement in Python

What is elif?

• elif stands for "else if." It allows you to check multiple conditions in a sequence.

• It is used after an if statement and before an else statement.

Why Use elif?


• To handle more than two conditions without nesting multiple if statements.

• Makes the code cleaner and easier to read.

Structure of if, elif, and else

Example of Using elif

Here’s a simple program that checks a person's age and prints a message based on the age
group:

How It Works

• Input: The user enters their age.

• Condition Checks:

• If the age is less than 13, it prints "You are a child."

• If the age is 13 or more but less than 20, it prints "You are a teenager."
• If the age is 20 or more but less than 65, it prints "You are an adult."

• If none of the above conditions are true (age 65 or older), it prints "You are a
senior."

Key Points

• You can have multiple elif statements to check different conditions.

• The first true condition will execute its block of code, and the rest will be skipped.

• The else statement is optional and will execute if none of the if or elif conditions are
true.

1. Loops: Doing Things Again and Again!


• Imagine you need to print the numbers 1 to 5. You could write:

But what if you needed to print numbers up to 100? That would be a lot of typing! That's where
loops come in handy. They let you repeat a block of code multiple times.

• for number in [1, 2, 3, 4, 5]:: This line says, "For each item in this list [1, 2, 3, 4, 5], let's
call that item number for now."

• print(number): This line is inside the loop. It will run once for each number in the list.

You can also use range() to easily create a sequence of numbers:

This creates numbers 1, 2, 3, 4, 5 (starts at 1, goes up to but not including 6))

• range(5) starts at 0 and goes up to (but doesn't include) 5.


• range(1, 6) starts at 1 and goes up to (but doesn't include) 6.

b) while Loops: Repeating While a Condition is True

A while loop keeps running as long as a certain condition is true. Be careful, though! If the
condition never becomes false, the loop will run forever (an infinite loop!).

# This is important to make the condition eventually become false!

counter = 1: We start with a variable called counter set to 1.

while counter <= 5:

This is the condition. The code inside the loop will keep running as long as counter is less
than or equal to 5.

print(counter): We print the current value of counter.

counter = counter + 1: We increase the value of counter by 1. This makes sure that
eventually counter will become 6, and the loop will stop.

When to use which loop?

• Use for loops when you know how many times you want to repeat something (like
going through a list or a specific range of numbers).

• Use while loops when you want to repeat something until a certain condition is met
(and you don't necessarily know how many times that will take).

2. Functions: Little Blocks of Reusable Code!


• Imagine you have a set of instructions that you need to use multiple times in your
program. Instead of writing those instructions out every single time, you can put them
into a function.

a) Creating a Function (Defining)


You define a function using the keyword def, followed by the function's name,
parentheses (), and a colon :. The code that the function will run is indented
underneath.
def greet():: This line defines a function called greet. It doesn't take any information
(that's what the empty parentheses mean).

The indented lines are the body of the function – the instructions it will follow.

b) Using a Function (Calling)

To make the function run, you need to call it by its name followed by parentheses:

This will print:

c) Functions with Inputs (Parameters)

You can give functions information to work with by using parameters inside the parentheses
when you define the function.

def greet_by_name(name):: The name inside the parentheses is a parameter. When you call
the function, you need to provide a value for this parameter.
d) Functions that Give Back Output (Return Values)

Sometimes you want a function to calculate something and give you the result back. You can
do this using the return keyword.

return sum_of_numbers: This line tells the function to send the value of sum_of_numbers
back to where the function was called.

result = add_numbers(5, 3): Here, we call the add_numbers function with 5 and 3 as inputs.
The function calculates the sum (8) and returns it. This returned value is then stored in the
variable result.

3. Data Types: Different Kinds of Information

Think of data types as labels that tell Python what kind of information you're working with.
Here are some important ones:
Integer (int): Whole numbers (positive, negative, or zero) without any decimal point

Float (float): Numbers with a decimal point.

String (str): Sequences of characters (letters, numbers, symbols) enclosed in single quotes (')
or double quotes (").

Boolean (bool): Represents truth values: either True or False. These are often used in
conditions (like in while loops and if statements).
List (list): An ordered collection of items. Lists are enclosed in square brackets [] and items
are separated by commas. You can store different data types in the same list.

Why are data types important?

Python needs to know the data type of something to understand what operations you can
perform on it. For example, you can add two integers together, but you can't easily add an
integer and a string (unless you convert the integer to a string first!).

You can check the data type of a variable using the type() function:

4. Basic Algorithms: Step-by-Step Instructions!

An algorithm is like a recipe – a set of clear instructions to solve a problem or achieve a


specific task. In programming, we write algorithms using code. Here are a couple of simple
examples you can implement in Python:

Alright, let's make some notes on loops, functions, data types, and basic algorithms, just like
you'd learn them in Year 8 in a British school!

Python Notes for Year 8

Here's a breakdown of those important Python concepts:

1. Loops: Doing Things Again and Again!

Imagine you need to print the numbers 1 to 5. You could write:

Python

print(1)
print(2)

print(3)

print(4)

print(5)

But what if you needed to print numbers up to 100? That would be a lot of typing! That's
where loops come in handy. They let you repeat a block of code multiple times.

a) for Loops: Repeating for a Set Number of Times

Think of a for loop like going through a list of things, one by one.

Python

for number in [1, 2, 3, 4, 5]:

print(number)

• for number in [1, 2, 3, 4, 5]:: This line says, "For each item in this list [1, 2, 3, 4, 5],
let's call that item number for now."
• print(number): This line is inside the loop. It will run once for each number in the
list.

You can also use range() to easily create a sequence of numbers:

Python

for i in range(5): # This creates numbers 0, 1, 2, 3, 4

print(i)

for count in range(1, 6): # This creates numbers 1, 2, 3, 4, 5 (starts at 1, goes up to but not
including 6)

print(count)

• range(5) starts at 0 and goes up to (but doesn't include) 5.


• range(1, 6) starts at 1 and goes up to (but doesn't include) 6.

b) while Loops: Repeating While a Condition is True

A while loop keeps running as long as a certain condition is true. Be careful, though! If the
condition never becomes false, the loop will run forever (an infinite loop!).

Python
counter = 1

while counter <= 5:

print(counter)

counter = counter + 1 # This is important to make the condition eventually become false!

• counter = 1: We start with a variable called counter set to 1.


• while counter <= 5:: This is the condition. The code inside the loop will keep
running as long as counter is less than or equal to 5.
• print(counter): We print the current value of counter.
• counter = counter + 1: We increase the value of counter by 1. This makes sure that
eventually counter will become 6, and the loop will stop.

When to use which loop?

• Use for loops when you know how many times you want to repeat something (like
going through a list or a specific range of numbers).
• Use while loops when you want to repeat something until a certain condition is met
(and you don't necessarily know how many times that will take).

2. Functions: Little Blocks of Reusable Code!

Imagine you have a set of instructions that you need to use multiple times in your program.
Instead of writing those instructions out every single time, you can put them into a function.

a) Creating a Function (Defining)

You define a function using the keyword def, followed by the function's name, parentheses (),
and a colon :. The code that the function will run is indented underneath.

Python

def greet():

print("Hello!")

print("Welcome to my program!")

• def greet():: This line defines a function called greet. It doesn't take any information
(that's what the empty parentheses mean).
• The indented lines are the body of the function – the instructions it will follow.

b) Using a Function (Calling)

To make the function run, you need to call it by its name followed by parentheses:

Python
greet()

This will print:

Hello!

Welcome to my program!

c) Functions with Inputs (Parameters)

You can give functions information to work with by using parameters inside the parentheses
when you define the function.

Python

def greet_by_name(name):

print("Hello, " + name + "!")

• def greet_by_name(name):: The name inside the parentheses is a parameter. When


you call the function, you need to provide a value for this parameter.

Python

greet_by_name("Alice") # Calling the function with the name "Alice"

greet_by_name("Bob") # Calling the function with the name "Bob"

This will print:

Hello, Alice!

Hello, Bob!

d) Functions that Give Back Output (Return Values)

Sometimes you want a function to calculate something and give you the result back. You can
do this using the return keyword.

Python

def add_numbers(num1, num2):

sum_of_numbers = num1 + num2

return sum_of_numbers

result = add_numbers(5, 3)
print(result) # Output: 8

• return sum_of_numbers: This line tells the function to send the value of
sum_of_numbers back to where the function was called.
• result = add_numbers(5, 3): Here, we call the add_numbers function with 5 and 3 as
inputs. The function calculates the sum (8) and returns it. This returned value is then
stored in the variable result.

Why are functions useful?

• Organisation: They help break down your code into smaller, manageable chunks.
• Reusability: You can use the same function multiple times without rewriting the
code.
• Readability: Functions make your code easier to understand.

3. Data Types: Different Kinds of Information

Think of data types as labels that tell Python what kind of information you're working with.
Here are some important ones:

• Integer (int): Whole numbers (positive, negative, or zero) without any decimal point.

Python

age = 13

score = -5

count = 100

• Float (float): Numbers with a decimal point.

Python

height = 1.55

temperature = 23.7

pi = 3.14159

• String (str): Sequences of characters (letters, numbers, symbols) enclosed in single


quotes (') or double quotes (").

Python

name = "Charlie"

subject = 'Maths'

message = "Hello, world!"


• Boolean (bool): Represents truth values: either True or False. These are often used in
conditions (like in while loops and if statements).

Python

is_raining = False

has_finished_homework = True

• List (list): An ordered collection of items. Lists are enclosed in square brackets [] and
items are separated by commas. You can store different data types in the same list.

Python

friends = ["Alice", "Bob", "Charlie"]

numbers = [1, 5, 2, 8]

mixed_list = [10, "hello", 3.14, True]

• Tuple (tuple): Similar to lists, but they are immutable, which means you can't
change them after they are created. Tuples are enclosed in parentheses ().

Python

coordinates = (10, 20)

colours = ("red", "green", "blue")

Why are data types important?

Python needs to know the data type of something to understand what operations you can
perform on it. For example, you can add two integers together, but you can't easily add an
integer and a string (unless you convert the integer to a string first!).

You can check the data type of a variable using the type() function:

Python

age = 13

print(type(age)) # Output: <class 'int'>

name = "Charlie"

print(type(name)) # Output: <class 'str'>

4. Basic Algorithms: Step-by-Step Instructions!


An algorithm is like a recipe – a set of clear instructions to solve a problem or achieve a
specific task. In programming, we write algorithms using code. Here are a couple of simple
examples you can implement in Python:

Finding the Largest Number in a List:

How this algorithm works:

1. We start by assuming the first number in the list is the largest.


2. We go through each number in the numbers list.
3. For each number, we check if it's greater than the current largest number we've
found.
4. If it is greater, we update the largest variable to store this new larger number.
5. After checking all the numbers, the largest variable will hold the biggest number in
the list.

What is an Assignment in Programming?


An assignment in programming refers to the process of storing a value in a variable.
It involves using the assignment operator, which is typically the equals sign (=).

Key Points
• Variable: A named storage location in memory.
• Assignment Operator: The = symbol that assigns a value to a variable.

How It Works
• Declare a Variable: Create a variable to hold data.
• Assign a Value: Use the assignment operator to set the variable's value.
Explanation of the Example

age = 25: The variable age now holds the value 25.

name = "Alice": The variable name now holds the string "Alice".

height = 5.5: The variable height now holds the decimal number 5.5.

Important Notes

• You can change the value of a variable by reassigning it.


• The variable name should be descriptive to indicate what it represents
(e.g., age, name, height).

Example of Reassignment
Getting Ready (The First Line):

Think of this like getting a special dice that has numbers on it. The word
random means things will happen in a way you can't predict. randint is like
saying, "I want a random whole number from a certain range." We're telling
the computer we want to use this special random number dice.

2. Picking the Numbers (The Next Two Lines):

Imagine the computer rolls that special dice twice.

• a = randint(2, 12): The first roll gives a number between 2 and 12 (it could be 2, or 3,
or 7, or even 12!). This number is now called "a" in our game.
• b = randint(2, 12): The computer rolls the dice again and gets another number
between 2 and 12. This number is now called "b".

So, "a" and "b" are just secret random numbers the computer has picked for your
multiplication question.

3. Playing Forever (The while True: Part):

This is like saying, "Keep playing this game over and over until someone says 'stop' (which
in this case, only you can do by closing the program)." The word while means "as long as
something is true," and True is always true, so the game will just keep going.
4. Asking the Question (The print Line):

Now the computer shows you the question using the secret numbers it picked: It prints the
value of "a", then the word "times", then the value of "b", and finally an equals sign. For
example, if "a" was 5 and "b" was 8, it would show you: 5 times 8 =

Okay, imagine you're playing a math game with a computer! This code is like the set of
rules for that game. Let's break it down in even simpler terms:

1. Getting Ready (The First Line):

Python

from random import randint

Think of this like getting a special dice that has numbers on it. The word random means
things will happen in a way you can't predict. randint is like saying, "I want a random whole
number from a certain range." We're telling the computer we want to use this special
random number dice.

2. Picking the Numbers (The Next Two Lines):

Python

a = randint(2, 12)

b = randint(2, 12)

Imagine the computer rolls that special dice twice.

• a = randint(2, 12): The first roll gives a number between 2 and 12 (it could be 2, or 3,
or 7, or even 12!). This number is now called "a" in our game.
• b = randint(2, 12): The computer rolls the dice again and gets another number
between 2 and 12. This number is now called "b".

So, "a" and "b" are just secret random numbers the computer has picked for your
multiplication question.

3. Playing Forever (The while True: Part):

Python
while True:

This is like saying, "Keep playing this game over and over until someone says 'stop' (which
in this case, only you can do by closing the program)." The word while means "as long as
something is true," and True is always true, so the game will just keep going.

4. Asking the Question (The print Line):

Python

print(a, "times", b, "=")

Now the computer shows you the question using the secret numbers it picked: It prints the
value of "a", then the word "times", then the value of "b", and finally an equals sign. For
example, if "a" was 5 and "b" was 8, it would show you: 5 times 8 =

5. Waiting for Your Answer (The input Line):

This is where it's your turn!

• input(): The computer waits for you to type something on the keyboard and press
the Enter key. Whatever you type is treated as text at first.

• int(...): Because we need to compare your answer to a number, int() tries to turn your
text answer into a whole number. If you type something that's not a number (like
"hello"), the game might get confused and stop.

Whatever number you type in is stored in a box called answer.

6. Figuring Out the Right Answer (The product Line):


While you were thinking, the computer quickly calculated the correct answer by
multiplying its secret numbers "a" and "b". It stores this correct answer in a box called
product.

7. Checking if You're Right (The if Part):

Now the computer checks if the number you typed in (answer) is exactly the
same as the correct answer it calculated (product). The == means "is equal to?".

8. Telling You "Correct!" (Inside the if):

If your answer is the same as the product, the computer says, "that is correct"!

9. Telling You "Sorry, Wrong Answer" (The else Part):

If your answer is not the same as the product, the computer says, "I am
sorry" and then tells you what the correct answer was by showing you
"a", "times", "b", "is", and the actual product.

And then...

Because of the while True: at the beginning, the whole process starts
again! The computer picks two new random numbers, asks you to
multiply them, and checks your answer. This continues until you close
the program.

You might also like