Fundamental Components of Programs (Edexcel GCSE Computer Science)

Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Constants, Variables, Initialisation & Assignment

Constants

  • A constant is an identifier set once in the lifetime of a program

  • Constants are named in all uppercase characters

  • Constants aid the readability and maintainability

  • If a constant needs to be changed, it should only need to be altered in one place in the whole program

Python examples

PI = 3.142

VAT = 0.20

PASSWORD = "letmein"

Variables

  • A variable is an identifier that can change in the lifetime of a program

  • Variables are named in lowercase characters unless combining multiple words

  • A variable can be associated a datatype when it is declared

  • When a variable is declared, memory is allocated based on the data type indicated

Python examples

score = int() # whole number

cost = float() # decimal number

light = bool() # data can only have one or two values

Initialisation & assignment

  • A variable can be initialised with a value

  • The assignment operator = is used to set or change the value of a variable

Python examples

score = 10 # Initialise with a value

cost = 9.50 # Initialise with a value

count = count + 1 # Adds one to the current value of count

Inputs & Outputs

Inputs

  • The input() function is used to capture an input from the user

  • All inputs default to strings and may need converting to the required data type in the program

Python examples

surname = input("Enter your surname: ")

examScore = int(input("Enter your exam score: "))

height = float(input("Enter height: "))

Outputs

  • The print() function is used to output to the screen

Python examples

print("Hello world")

examScore = 90

print(examScore)

print("Exam score: ", examScore)

  • An output can be formatted to the users needs using string formatting {}

Python examples

print("{:.2f}".format (price)) # Displays a currency value to two decimal places

print(f"Pi approximation: {pi_approx}") # Displays a variable formatted as a string with a label

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.