University of Glasgow · S1 2026 · FACULTY OF COMPUTER SCIENCE

COMPSCI4039 Programming

- one subject, every graph, every model, every mark
10 Chapters49-page Bible
Our own words - no uploaded lecturer files
Built to mirror S1 2026 · updated this semester
The Complete Exam Bible · Semester 1 2026/27

COMPSCI4039 Overview

Programming
— read Python precisely, trace it line by line and write it with confidence
  • University of Glasgow
  • Semester 1 2026/27
  • 10 chapters
  • Computer Science

COMPSCI4039 Programming is the Python foundation course of the MSc IT+ programme at the University of Glasgow. The course states plainly that it is mainly about understanding programs and the kinds of computation behind them; writing small programs is the route to that understanding rather than an end in itself.

  • Assessed by Coursework worth 25% and a December examination worth 75%.
  • Hardest step Tracing state exactly: types, scopes, shared lists and loop boundaries.
  • Exam aid A crib sheet of key syntax is provided; the exam is not open book.
  • How to prepare Predict output on paper before running anything, every day.
COMPSCI4039 · University of Glasgow
An independent, AskSia-authored study guide. AskSia is not affiliated with, endorsed by, or sponsored by University of Glasgow; the course code and name are used for identification only.
Assessment

How COMPSCI4039 is assessed

ComponentWeightFormat
Quizzes in lecture7%Seven quizzes in weeks 2 to 8, each worth 1%, sat under supervision in the lecture theatre.
Major programming exercise8%Individual coursework submitted in week 9. The Moodle assignment opens on 30 September 2026 and closes at 4:30 PM on Friday 20 November 2026.
In-lab test10%Supervised coursework test in the lab in week 10, based on the major programming exercise.
Written exam75%December 2026 exam diet, a digital on-campus exam supervised in the exam hall. It blends program understanding and program writing; it is not open book, and a two-to-four-page crib sheet of key syntax is provided.

Weights come from the opening lecture's assessment slide and agree with the University course catalogue, which lists assessed exercise 25% and examination 75%. Exact examination date and duration are not given in the course materials; use your personal timetable.

Current dates · verify in LMS

Current COMPSCI4039 dates

DateItemControl
20 November 2026Major programming exercise dueThe Moodle assignment is due at 4:30 PM and carries 8% of the course grade.
December 2026Examination dietThe digital on-campus examination worth 75% falls in the December diet; the exact date is on your personal timetable.

Dates are as published in the Semester 1 2026/27 Moodle course page and assessed exercise page. Confirm exact deadlines and submission settings in the live LMS.

Contents · every chapter, one map

What COMPSCI4039 covers

Ten chapters follow the intensive opening week, from values and expressions through functions, scope, selection and loops to strings, lists, dictionaries and files.

01

Values, Variables and Types

Monday lecture. The ABC modelling view, print and input, name and value bindings, literals, types and the two kinds of error.

Values, Variables and Types sets up the mental model every later chapter depends on. A program is a precise sequence of instructions, and the machine carries them out literally, even when they make no sense.

  • The ABC view of programming as modelling
  • Output with print, input and the input-process-output style
  • Variables as name and value associations
  • Dynamic typing and reassignment
  • Literals of type str, int, float and bool
  • Naming rules and comments
02

Expressions and Type Casting

Operator precedence, true and floor division, the remainder operator, float approximation, shortcut operators and casting between types.

Expressions and Type Casting covers how Python turns operators and operands into a single value, and how to move a value between types on purpose.

  • Expressions, operands and operators
  • Precedence, brackets and left-to-right evaluation
  • True division, floor division and remainder
  • Float results and float approximation
  • Shortcut assignment operators
  • Casting with int, float, str and bool
03

Functions and Return Values

Tuesday lecture. Definitions and calls, execution flow, parameters and arguments, return versus print, and functions calling functions.

Functions and Return Values introduces the first building block that changes how a program executes.

  • Why repeated code belongs in a function
  • The def header and the indented body
  • Execution flow through calls and returns
  • Parameters and arguments
  • Return versus print, and the value None
  • Functions that call other functions
04

Scope and Tracing Function Calls

Local and global variables, reused names in separate scopes, the global keyword and tracing what a call can and cannot change.

Scope and Tracing Function Calls explains how names are kept apart once a program contains functions. Each call creates its own local variables, including its parameters, and those names vanish when the call ends.

  • Local variables and the lifetime of a call
  • Global variables in the main body
  • Reused names in separate scopes
  • Why reassigning a parameter cannot change the caller
  • Name errors from using a local outside its function
  • The global keyword
05

Selection and Boolean Conditions

The if, elif and else statements, comparison and logical operators, boolean variables, nested decisions and choosing test cases.

Selection and Boolean Conditions gives programs the ability to act differently depending on the data they hold. A selection statement asks a question of the program's state and runs a block only when the answer is True.

  • Conditions as questions about program state
  • The if, else and elif statements
  • First-true-wins and the order of tests
  • Comparison operators and equality with ==
  • Logical operators and boolean variables
  • Nested selection and tracing one path
06

Loops and the Range Function

Wednesday lecture. The while and for loops, range arguments, simulated do-while loops, break and continue, infinite and nested loops.

Loops and the Range Function introduces repetition, the building block that lets a few lines process any number of items.

  • Why repetition replaces copied lines
  • While loops and continuing conditions
  • Infinite loops and how to avoid them
  • For loops over range and over lists
  • Range with start, stop and step
  • Simulated do-while loops with break and continue
07

Input and String Formatting

String operators, special characters, keyboard input and splitting, and f-string field widths, alignment, zero padding and decimals.

Input and String Formatting gathers the tools for getting text into a program and laying results out neatly. Strings have their own operators: plus joins two strings without adding a space, and star repeats a string a given number of times.

  • String concatenation and repetition
  • Special characters and print's end argument
  • Reading keyboard input as strings
  • Casting and splitting typed input
  • Format specifications inside f-strings
  • Width, alignment and zero padding
08

Lists, Tuples and Aliasing

Thursday lecture. Indexing, list methods, nested lists, shared references between names, tuples and returning several values.

Lists, Tuples and Aliasing introduces collections, which let one name stand for many values. A Python list is an ordered collection whose elements are reached by integer indexes starting at 0, much like a set of variables named by position.

  • Why programs need collections
  • Creating lists and growing them with append
  • Indexing from 0 and updating elements
  • List methods and the length function
  • Shared references after assignment
  • Nested lists and shared inner lists
09

Dictionaries and Sets

Index-style and record-card dictionaries, keys and look-up, counting with get, key collisions and set operations.

Dictionaries and Sets covers collections in which items are reached by a key rather than a position.

  • Keys instead of positions
  • Index-style and record-card dictionaries
  • Creating, reading, updating and adding entries
  • Membership tests and looping over keys
  • Counting with get and a default
  • Unique keys and overwriting
10

File Handling and Program Structure

Friday lecture. Opening, reading and writing files, file modes, exceptions, CSV processing, libraries and the main-function pattern.

File Handling and Program Structure closes the opening week by connecting programs to permanent storage and by showing how larger programs are organised.

  • Files, folders, paths and the working directory
  • Opening files safely with with
  • Reading with read, readline, readlines and loops
  • Newlines and strip
  • Write, append, exclusive and binary modes
  • Catching file errors with try and except

That emphasis matters because generative AI can now produce short programs quickly, and employers expect graduates to verify such output. Verification is only possible for someone who can read code precisely.

Teaching begins with an intensive first week: a two-hour lecture each day, a daily examples class from Tuesday and lab sessions to work through exercise sheets.

Monday introduces the ABC view of computing, first programs, variables and types. Tuesday covers functions, scope and selection. Wednesday adds loops, string formatting and libraries. Thursday turns to data structures: lists, tuples, dictionaries and sets. Friday closes with file handling and the structure of larger programs.

From week 2, the opening lecture describes a weekly rhythm of two two-hour lectures and a lab, with a quiz on the week's material in lecture during weeks 2 to 8.

The assessment has two layers. Coursework carries 25%: seven in-lecture quizzes worth 1% each, a major programming exercise worth 8%, and an in-lab test worth 10% that builds on that exercise.

The December examination carries 75% and tests both reading and writing code. It is not open book, although a crib sheet of two to four pages with key syntax is provided. Success therefore depends on fast, accurate tracing: knowing exactly what a fragment prints, which branch runs, what a call returns and which names share a list.

Worked example · free

Trace a call that cannot change its caller's variable

Q [5 marks]. A program sets count = 4, defines def bump(count): count = count + 10; return count, then runs result = bump(count) and print(count, result). What is printed, and why is count unchanged? (The mark allocation shown is a learning aid of our own and not a university marking scheme.)
The main scope and the function scope each hold a variable called amount.The main scope and the function scope each hold a variable called amount. The call binds its parameter to the value 40, the function updates only its own amount to 42.5, and only the returned 42.5 comes back.main scopeadd_fee scopeamount40total42.5amount42.5fee2.5value 40 copied inreturn 42.5
The main scope and the function scope each hold a variable called amount. The call binds its parameter to the value 40, the function updates only its own amount to 42.5, and only the returned 42.5 comes back.
  • 1Main binds count to 4. The definition of bump is skipped until it is called.
  • 1The call creates a new local variable count inside bump and sets it to the argument value 4.
  • 1The body rebinds the local count to 14 and returns 14, so main binds result to 14.
  • 1The local count disappears when the call ends; main's count was never rebound and still holds 4.
  • 1The print shows both values separated by one space: 4 14.
The program prints 4 14. The two variables called count live in different scopes, and only the returned value crosses back to the caller.
Sia tip — Draw one box for main and one for the call, then write each name only in the box that owns it.
Glossary

Key terms

Variable
A name linked to a value, where the link can be updated as a program runs.
Literal
A value typed directly into program text, such as 42, 3.5, True or a quoted string.
Expression
Any piece of program text that produces a value when it is evaluated.
Casting
Converting a value to another type with a function such as int, float, str or bool.
Parameter
A name in a function header that receives the value supplied by each call.
Return statement
The line that ends a function call and sends one value back to the caller.
Local scope
The region in which names created inside a function exist, visible only during that call.
Conditional expression
A test that evaluates to True or False and decides whether a block of code runs.
Range
A built-in function that produces evenly spaced integers up to, but not including, a stop value.
F-string
A string prefixed with f whose braces insert values with optional width, alignment and precision.
List method
A function attached to the list type, such as append or pop, that changes or reads a list.
Dictionary key
The unique value used to store and look up an entry in a Python dictionary.
File mode
The second argument to open, such as r, w, a or x, that controls how a file is used.
FAQ

COMPSCI4039 FAQ

How difficult is this course?

The difficulty lies in precision rather than volume. The opening week packs five lectures of new building blocks into five days, and the December examination, worth three quarters of the grade, asks you both to explain existing code and to write new code without AI help. The course itself recommends predicting output by hand before running anything, and every later topic builds on that habit.

How is the course assessed?

Coursework is worth 25%: seven quizzes in lecture at 1% each, a major programming exercise at 8% and an in-lab test at 10% that builds on the exercise. The written examination in the December diet is worth 75%. The University course catalogue records the same 25 and 75 split between assessed exercise and examination.

What is the final exam format?

The opening lecture calls it a written exam combining program understanding and program writing, and the course page lists it as a digital on-campus exam in the December 2026 diet. Expect tracing questions on given code alongside tasks that ask for short functions. The materials do not state the duration, so confirm it on your personal timetable.

Can I take notes into the exam?

No. The lecturers answered this directly in the second lecture: the exam is not open book. Instead the course provides a crib sheet of two to four pages containing key information such as Python syntax, so that memorising every detail of the language is unnecessary. The reasoning about what code does still has to come from you.

Are past exam papers available here?

The course materials available here include examples-class sheets with solutions, lab exercise sheets and formative quizzes, but no past examination paper. The practice in this guide is therefore original and follows the question types those sheets demonstrate: predicting output, explaining errors, completing format tables and writing small functions.

Can I use generative AI on this course?

Only in limited places. The course guidance lists four principal assessments and treats three of them, the lecture quizzes, the coursework test and the degree exam, as supervised with no AI access. The coursework exercise allows broad use. For learning, the guidance recommends asking AI to explain or to challenge you rather than to write your code.

What should I revise first for December?

Start with tracing fundamentals: assignment, operator precedence, the difference between return and print, and scope. Then drill selection order, loop boundaries and list aliasing, since many examples-class questions turn on them. Finish with dictionaries, string formatting and file modes, writing each small function from a blank page and testing it on a value you can check by hand.

Chapter questions

Questions students ask in each COMPSCI4039 chapter

Why does Python not ask for a variable type?
Python is dynamically typed: each value carries its own type, and a name simply points at whichever value was assigned last. That makes short programs quick to write but means a careless reassignment can silently replace a number with text. Chapter 01 · Values, Variables and Types
Why does 8 / 2 print 4.0 instead of 4?
In Python the single slash is true division and always returns a float, even when both operands are whole numbers and the division is exact. Use the double slash when you want whole-number division of two ints. Chapter 02 · Expressions and Type Casting
Why does my function print the right value but return None?
Printing inside a function only displays text; it does not hand anything back. Without a return statement the call evaluates to None, so storing or printing its result shows None. Replace the inner print with return when the caller needs the value. Chapter 03 · Functions and Return Values
Why does my function not change the variable I passed in?
The call binds a new local parameter to the argument's value. Reassigning that parameter inside the function changes only the local name, so the caller's variable is untouched. Return the new value and assign it in the caller instead. Chapter 04 · Scope and Tracing Function Calls
Why does my elif chain give the wrong grade?
Python runs only the first branch whose condition is True and skips the rest. If a looser test sits above a stricter one, the looser branch catches values meant for later branches. Order the conditions from most specific to least specific. Chapter 05 · Selection and Boolean Conditions
Why does range(1, 10) stop at 9?
The stop argument of range is always excluded, so range(1, 10) produces 1 to 9. To include 10 you would write range(1, 11). This exclusion is the most common source of off-by-one answers in loop questions. Chapter 06 · Loops and the Range Function
Why does input give me a string even when I type a number?
input always returns exactly what was typed as text. To calculate with it, wrap the call in int or float, as in int(input()). Without the cast, multiplying the value repeats the text instead of doing arithmetic. Chapter 07 · Input and String Formatting
Why did changing one list change another?
Assignment such as m = a does not copy a list; it makes a second name for the same object. Updating an element through either name changes that shared object, so both names show the change. Chapter 08 · Lists, Tuples and Aliasing
What happens if I look up a key that is not there?
Square-bracket look-up of a missing key stops the program with an error. Check first with the in operator, or use get with a default value, which returns the default instead of failing. Chapter 09 · Dictionaries and Sets
Why does my file lose its old contents?
Opening a file in mode w creates it if necessary and empties it if it already exists, so earlier data is lost. Use mode a to add to the end while keeping existing contents, or mode x to refuse when the file is already there. Chapter 10 · File Handling and Program Structure
Study strategy

How to study for the exam

Treat COMPSCI4039 as training in reading code before writing it. Each day, take a short fragment from your notes or this guide, predict its output in writing, then run it and explain any difference. Keep a state table for every trace, with one column per name and a new row after each executed line.

Work through the topics in the order the course taught them, because every chapter depends on the one before: assignment and types underpin expressions, functions rely on both, scope only makes sense once functions do, and lists and dictionaries combine all of it with loops. For writing practice, solve each lab-style task on paper first, naming the inputs, the output and the structures you need, and only then type it.

Test every function on at least one value whose answer you can work out by hand and one awkward value such as an empty list. In the final weeks before December, alternate a tracing session with a writing session, and log each mistake by its cause, such as a missing cast, an off-by-one range, a lost return value or an unexpected shared list, rather than by topic name.

Study COMPSCI4039 with AI

Your AI Computer Science tutor for COMPSCI4039

Stuck on a hard COMPSCI4039 question? Sia is AskSia’s AI Computer Science tutor — ask any COMPSCI4039 Programming question and get a clear, step-by-step explanation grounded in how the course is actually taught and assessed. Read this whole study guide free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 26 of your subjects at University of Glasgow, plus 1,000+ more Bibles across the AskSia library.
Sia - your COMPSCI4039 tutor, unlimited, worked the way the exam marks it
The full 49-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works