MM1041 Chap.11 Python Programming Fundamentals
Python Programming Fundamentals
Why Python carries weight here
Fundamental Python programming skills are one of the course's five learning outcomes. The published schedule places two Python sessions in Weeks 12 and 13, the Python Exercises in Week 13 are a graded component, the exam rubric assesses Python skills, and the group project names Python applications as one possible analysis method.
The course recommends Google Colab and Kaggle notebooks, which run in a web browser, so no installation is needed.
Values, variables and operators
A Python program works on values: whole numbers, decimals, text strings and the truth values True and False. A variable is a name bound to a value by a single equals sign.
Arithmetic uses the familiar operators, but division comes in three forms: a single slash gives the exact quotient, a double slash gives the quotient rounded down, and the percent sign gives the remainder. The remainder is what tests whether a number is even.
Conditions and loops
An if statement runs a block only when its condition is True, with optional elif and else branches.
Conditions use comparison operators such as double equals and greater-than-or-equal, and combine with and, or and not. A for loop repeats a block once for each item in a sequence, which is how a script totals a list of sales or checks every order against a threshold.
Indentation marks which lines belong to each block.
Lists and functions
A list stores values in order, with positions counted from zero, and len gives its length. A function packages steps under a name, takes parameters and returns a result, so the same logic can be reused on new data.
These pieces are enough to write small analyses, such as counting large orders or averaging daily sales, that echo the data analytics ideas of the earlier chapters.
Working in a notebook
In Colab or Kaggle, code sits in cells run one at a time, and variables persist in the order cells were run. Restarting and running everything from the top is the first fix for a confusing result.
Comments after a hash sign explain each step to your group and to a marker.
What this chapter covers
- 01
Why Python appears in the learning outcomes
- 02
Values, types and variables
- 03
Division, floor division and remainder
- 04
If, elif and else
- 05
For loops over lists
- 06
Functions with parameters and return values
- 07
Notebooks in Colab and Kaggle
Worked example · free
Trace a short sales script
- 3Trace the loop and give the count.
- 3Evaluate the condition and give the final output.
Key terms
- Variable
- A name bound to a value so that later lines of a program can use it.
- Floor Division
- Division that rounds the quotient down to a whole number, written with a double slash.
- Remainder Operator
- The percent sign, which gives what is left over after division.
- For Loop
- A structure that repeats a block of code once for each item in a sequence.
- Function
- A named block of code that takes parameters and returns a result.
- List Index
- The position of an item in a list, counted from zero.
- Notebook Cell
- A block of code in a notebook such as Colab or Kaggle that is run on its own.
Python Programming Fundamentals FAQ
Do I need to install anything to program in Python for this course?
No. The course recommends Google Colab and Kaggle notebooks, which run in a web browser with nothing to install. Sign in, create a notebook and type code into a cell. Practising in the same tool you will use for the graded exercises removes one source of stress on the day.
Why does my code say a variable is not defined when I can see it?
In a notebook, a variable exists only after the cell that creates it has been run. If you edited or reordered cells, or restarted the session, the definition may not have run yet. Restart and run all cells from the top; if the error remains, check the spelling, since Python treats upper and lower case as different names.
How do I test whether a number is even in Python?
Use the remainder operator: number % 2 == 0 is True exactly when the number is even. Floor division, number // 2, answers a different question, the whole-number half, so comparing it with zero is True only for 0 and 1. Try any rule on a few numbers before trusting it in an exercise.
Exam move
Type every snippet from this chapter into a Colab notebook and change one value in each to see what happens. Then write three tiny functions of your own, a total, a count above a threshold and an average, and test each on a list of five numbers where you already know the answer.
Working through Python Programming Fundamentals in MM1041? Sia is AskSia’s AI Information Technology tutor — ask any MM1041 Python Programming Fundamentals question and get a clear, step-by-step explanation grounded in how MM1041 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.