GCSE Computer Science (CCEA)

Topic Summaries

ALGORITHMS AND PROGRAMMING: Python

Basic structure of Python

  • Variables and data types:

name = “Kai”         # String

age = 16             # Integer

height = 1.68        # Float

is_student = True    # Boolean

  • Input and output:

name = input(“Enter name:”)

print(“Hello”, name)

  • Control flow:

# If statements

if age > = 18

print(“Adult”)

else:

print(“Child”)

 
 

# For loops

for i in range(5):

print(i)

 
 

# While loops

count = 0

while count < 5:

print(count)

count += 1

  • Lists (arrays):

fruits = [“apple”, “banana”, “cherry”]

print(fruits[1]) # Output: banana

  • Functions:

def greet(name):

print(“Hello” name)

greet(“Kai”)

  • Operators:

# Arithmetic

+ # Addition

# Subtraction

* # Multiplication

/ # Division

// # Integer division

% # Modulus

** # Exponentiation

 
 

# Comparison

== # Equal to

! = # Not equal to

> # Greater than

< # Less than

> = # Greater than or equal to

< = # Less than or equal to

 
 

Boolean

and # both True

or # at least one True

not # reverses value

Unlock Basic structure of Python

Sign up to unlock the rest of this topic — plus every other topic, video, flashcard set and eBook guide in your SnapRevise Digital subscription.

Cancel anytime — instant access the moment you sign up.