Ict Revision Coding
Ict Revision Coding
Key Components
• CPU (Central Processing Unit): The brain of the computer that processes
instructions.
• RAM (Random Access Memory): Temporary memory that stores data for quick
access.
• 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
Logical Operators
Logic Gates
• Logic Gates are like switches that control how data flows.
Programming Concepts
Variables
• Data Types:
• AI: Machines that can perform tasks that usually need human thinking.
• Ethical Questions: Concerns about privacy, fairness, and the impact of technology on
jobs.
What is elif?
• elif stands for "else if." It allows you to check multiple conditions in a sequence.
Here’s a simple program that checks a person's age and prints a message based on the age
group:
How It Works
• Condition Checks:
• 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
• 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.
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.
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 the condition. The code inside the loop will keep running as long as counter is less
than or equal to 5.
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.
• 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).
The indented lines are the body of the function – the instructions it will follow.
To make the function run, you need to call it by its name followed by parentheses:
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.
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
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.
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:
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
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.
Think of a for loop like going through a list of things, one by one.
Python
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.
Python
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)
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
print(counter)
counter = counter + 1 # This is important to make the condition eventually become false!
• 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).
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.
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.
To make the function run, you need to call it by its name followed by parentheses:
Python
greet()
Hello!
Welcome to my program!
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):
Python
Hello, Alice!
Hello, Bob!
Sometimes you want a function to calculate something and give you the result back. You can
do this using the return keyword.
Python
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.
• 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.
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
Python
height = 1.55
temperature = 23.7
pi = 3.14159
Python
name = "Charlie"
subject = 'Maths'
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
numbers = [1, 5, 2, 8]
• 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
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
name = "Charlie"
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
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.
• 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.
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:
Python
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.
Python
a = randint(2, 12)
b = randint(2, 12)
• 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.
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.
Python
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 =
• 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.
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?".
If your answer is the same as the product, the computer says, "that is correct"!
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.