You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the fundamental programming techniques required by the OCR A-Level Computer Science (H446) specification. These are the building blocks of all programs: sequence, selection, iteration, subroutines, and parameter passing.
Sequence is the most basic programming construct. Instructions are executed one after another, in the order they are written.
# Sequence: each line executes in order
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}, you are {age} years old")
Selection allows a program to choose between different paths of execution based on a condition. The condition evaluates to either True or False.
score = int(input("Enter score: "))
if score >= 90:
grade = "A*"
elif score >= 80:
grade = "A"
elif score >= 70:
grade = "B"
elif score >= 60:
grade = "C"
elif score >= 50:
grade = "D"
else:
grade = "U"
print(f"Grade: {grade}")
IF score >= 90 THEN
grade = "A*"
ELSEIF score >= 80 THEN
grade = "A"
ELSEIF score >= 70 THEN
grade = "B"
ELSE
grade = "U"
ENDIF
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.