This tutorial covers the essential programming concepts assessed in OCR GCSE Computer Science Paper 2.
Variables are containers that hold data. They are like labelled boxes you can store different values in.
name = "Alice"
age = 25
Constants are fixed values that cannot change. They are often used for values that remain the same throughout the program.
PI = 3.14159
Different types of data require different storage methods. Common data types include:
Operators are symbols that perform operations on data.
Arithmetic Operators:
Comparison Operators:
Logical Operators:
Input allows users to provide data to the program.
name = input("Enter your name: ")
Output displays information from the program.
print("Hello,", name)
Control Structures determine the flow of execution in a program.
5.1. Sequence
Statements are executed in the order they appear.
print("Step 1")
print("Step 2")
print("Step 3")
5.2. Selection (if-else)
Executes different code blocks based on a condition.
if age >= 18:
print("You are an adult")
else:
print("You are a minor")
5.3. Iteration (Loops)
Repeats a block of code multiple times.
5.3.1. For Loop: Repeats a fixed number of times.
for i in range(5):
print("Loop iteration:", i)
5.3.2. While Loop: Repeats as long as a condition is true.
count = 0
while count < 5:
print("Loop iteration:", count)
count += 1
Example 1: Calculating the area of a circle
PI = 3.14159
radius = float(input("Enter the radius: "))
area = PI * radius * radius
print("The area of the circle is:", area)
Example 2: Checking if a number is even or odd
number = int(input("Enter a number: "))
if number % 2 == 0:
print(number, "is even")
else:
print(number, "is odd")
Practice writing code using the concepts covered in this tutorial. Work through exercises and past papers to solidify your understanding. Remember to break down complex problems into smaller, manageable steps. Good luck with your GCSE Computer Science exams!