07/02/2026

Week 9 Assignments

1. Multiplication table - Advanced

Improve the multiplication table you did in class, by adding column and row headers, and separator lines.


   |  1  2  3  4  5  6  7  8  9
---+---------------------------
  1|  1  2  3  4  5  6  7  8  9
  2|     4  6  8 10 12 14 16 18
  3|        9 12 15 18 21 24 27
  4|          16 20 24 28 32 36
  5|             25 30 35 40 45
  6|                36 42 48 54
  7|                   49 56 63
  8|                      64 72
  9|                         81     

31/01/2026

Week 9 Learning Summary

 Week 9 subject 1: Nested loops

  • For loop inside a for loop
  • Different loop variables used
  • Note how many times the contents of the loop are executed
Week 9 subject 2: User input and while loops
  • Use input() to get a line of input
  • Provide prompt as argument to input()
  • Convert the return value of input() with int() or float()
  • while loops can be used to get repeated user input
  • Common while loops format:
    • Initial input() before entering the loops
    • additional input() as the final step inside the loop

13/12/2025

Week 8 Assignments

1. Leap Year

Input a year N (0 < N < 2999), output ‘Leap year’ if year N is a leap year, output ‘Not leap year’ if year N is not a leap year;  Note that year N is a leap year if N is divisible by 4 AND N is not divisible by 100; However year N is always a leap year if N is divisible by 400.

Extension 1: 

Output 'almost leap year' if N divisible by 4 but not actually a leap year. 

2. Parallelogram

Input an integer N and an integer M (0 < NM < 20), output a N by M parallelogram.  Example, N = 5, M = 4, output is

 
   *****
  *****
 *****
*****

Extension 1: 

Output both the original parallelogram and its mirror image.

Extension 2: 

Use ‘*’ and ‘+’ for alternating rows.

3. String operation

Input a string Name, a string Action, an integer Time.  Compose a sentence saying some is going to something at some time.  Example: Name = “Bryan”, Action = “Sleep”, Time = 22, Output: Bryan is going to Sleep at 22 o’clock.

Extension 1: 

Name can contain multiple words separated by ‘and’, in that case you’ll need to use ‘are’ instead of ‘is’.

Extension 2: 

Time can be in the past.  In that case you’ll need to use ‘was going to’ instead of ‘is going to’.  Not they may need to be adapted to plural forms as well.

4. Mind reader:

Your computer tells you it has mind reading capabilities.  You certainly don't buy that because you go to the Opportunity Class.  Your computer suggests a game with which it will show you that it reads your mind.

You give it a range, like 1..100, and the computer guesses an integer within that range.  All you need to do is tell it 'too large' or 'too small'.  You two repeat this Q&A until the computer guesses the correct number you have in mind.  By doing so you are able to tell if the computer can really read your mind, or it's simply doing maths.

Input 2 integers that indicate the range.  For each integer the computer guesses, input 'too large''too small''correct', or 'quit'.  The game ends when the input is 'correct' or 'quit'.  The computer outputs the integer you have in mind, and the number of guesses taken.  If the computer finds out you are trying to cheat, it also ends guessing and outputs 'you can't fool me!'.

Week 8 Learning Summary

 Week 8 subject 1: if - elif - else

if condition:
    actions...

if condition:
    actions...
else:
    other actions...

if condition1:
    actions...
elif condition2:
    more actions
elif condition3:
    more actions
else:
    other actions
  • Pay special attention to indentation and ":"
  • It's wise to always include an else.  Why?

Week 8 subject 2: match - case

match condition:

    case value1:

        actions...

    case value2:

        more actions...

    case value3:

        more actions...

    case _:

        other actions...

06/12/2025

Week 7 Learning Summary

 Week 7 subject 1: Lists (cont.)

  • Splitting strings into lists with .split()
  • Joining lists into strings with .join()
  • Replacing a substring in a string with .replace().  Also can using slicing of strings.
  • Can use loops to process strings, example:
    1. Get a line of input with input()
    2. Break line into list of words
    3. For each word change the first and last character to "*" and print

Week 6 and 7 Assignments

1. Stammer Bob: 

Bob stammers when facing long words.  He speaks all words with less than or equal to 5 letters fluently, but for each word with more than 5 letters, each extra letter causes him to repeat the word once more.  For example, when you say ‘Good Morning Bob’, he will have to reply ‘Good Morning Morning Morning George George’.  

Input a sentence, output how Bob actually pronounces it.

2. Looping

Input an integer N and an integer M (0 < NM < 20), output a N by M parallelogram.  Example, N = 5, M = 4, output is

 
   *****
  *****
 *****
*****

 

Extension 1: 

Output both the original parallelogram and its mirror image.


Extension 2: 

Use ‘*’ and ‘+’ for alternating rows.


3. Preprocessing:

You work for a big data company.  They take vast number of texts from the media and perform data analysis.  Your job is to preprocess the text by attaching data points to the words so that they can be processed by the data scientists.  The rule is simple: for each input line, separate them into words (delimited by spaces), prefix each word with the sequence number of it in the line, and suffix it with the length of the word.  For example, for the input ‘giant leap for mankind’, you produce an output ‘0giant5 1leap4 2for3 3mankind7’.

3. the Code


Criminals are threatening to blow up the city, you have only 24 hours to stop them.

The only thing you know is that they use the Bible as a code book.  We know that different words appear with difference frequencies in the Bible, apparently that's the hint to crack their code.  

You are given an extract from the bible.  Please break it into words, then sort them in the order of frequence appearing in the extract.  Give that result (a list of words sorted in the descending order of frequencies) to forensic scientist who will take it from there.

The clock is ticking.  Act NOW!

22/11/2025

Week 6 Learning Summary

    Week 6 subject 1: For Loops

    for variable in list or range:
        things to do…

    • Loop through a list
    • Pay special attention to indentation and ":"
    • Loop through a numerical range

    Week 6 subject 2: Lists (cont.)

    • List arithmetics: + and *
    • Generate lists from numerical ranges
    • Use lists from ranges with slicing
    • Advanced use of lists
      • for in list generator
      • if in list generator

    19/11/2025

    Week 5 Assignments

    1. Preprocessing:

    You work for a big data company.  They take vast number of texts from the media and perform data analysis.  Your job is to preprocess the text by attaching data points to the words so that they can be processed by the data scientists.  The rule is simple: for each input line, separate them into words (delimited by spaces), prefix each word with the sequence number of it in the line, and suffix it with the length of the word.  For example, for the input ‘giant leap for mankind’, you produce an output ‘0giant5 1leap4 2for3 3mankind7’.

    Input a line, output the outcome of the preprocessing with the additional data points attached.

    2. Lonely librarian:

    You are the only librarian in the school library.  You get sick of keeping record of new books and writing labels, you decide to create some automation.  You want to keep entering names of new books, until at one point you enter ‘end’so the automation stops.  For each book entered, it’s added to your record, unless the same name already exists in the record.  When the automation stops, it prints a list of all the books entered.

    Input a series of book names, output the list of books entered.

    Extension: 

    People make mistakes, a lonely librarian makes more.  When you discover a mistake, instead of entering the name of the book, you enter ‘del’ followed by the name of the book incorrectly entered.  The book is then removed from your list.  

    Input a number of book names and delete commands, output the final list of books.

    3. The more the merrier:

    You are organising 2 parties.  At one point it suddenly occurs to you: if people come to parties to have fun, why hold two when you can have everybody in one.  There’s twice the fun and you don’t have to work twice as hard.  You need to merge the 2 guest lists.  They are both sorted alphabetically.  You need a program to merge them so that the combined list is still sorted alphabetically.

    Input 2 lines, each containing a list of names sorted alphabetically, output a combined list of names sorted alphabetically.

    Week 5 Learning Summary

     Week 5 subject 1: Numbers (cont.)

    • Floating point numbers are numbers with decimal points
    • Floating point operations
      • Same as integers
      • % and // also works for floats!
    • Type conversion from int to float
      • Automatic and manual conversion with float()
    • Never compare if floats are equal!

    Week 5 subject 2: Lists

    • List is a Python advance data type.
    • There are list variables and list literals.
    • List is an ordered set of objects, can be of different types.
    • List elements can be accessed with subscripts (which makes Lists iterables), subscript ranges start at 0.
    • You can have lists as elements of lists.  Note one data element is different from one list with only one data element.  Example: “abc” is different from [“abc”].
    • Operating Lists: accessing elements with index,  .append()del, .pop(), .remove() (note they have different syntax).
    • Slicing: [begin:end:step], omitting begin or end, negative step

    01/11/2025

    Week 3 Assignments

    1. Clean format:

    Input a line of strings of mixed cases, format each word (words are strings delimited by spaces) so that they are capitalised.  Output the formatted line. 

    2. Stammer Bob: 

    Bob stammers when facing long words.  He speaks all words with less than or equal to 5 letters fluently, but for each word with more than 5 letters, each extra letter causes him to repeat the word once more.  For example, when you say ‘Good Morning Bob’, he will have to reply ‘Good Morning Morning Morning George George’.  

    Input a sentence, output how Bob actually pronounces it.

    3. Letter from Moscow:

    Your friend lives in Moscow.  He sends you email messages.  Because of the extreme cold, people have a different accent there.  They pause after each word, and at the end of each sentence they yell.  This even affects the way they write emails, for each word they write, they always add a comma after, and wherever we use a comma or full stop, they always use an ‘!’.  You may receive a message from Moscow saying ‘Good, day, mate! How, are, you! I, don’t, yell! I’m, just, friendly!’.

    Input a line of message, output the result after translating to the Moscow accent.

    4: Rome was not built in a day

    We all know that Rome was not built in a day.  Apparently Rome was built in a year.

    Store you name and your age in variables.  Then print out the name followed by the age when Rome is built if you start now.  For example, if name is 'George' and age is 12, then the output will be:

    'George, you'll be 13 years old when Rome is built.  So get started now!'

    Remember to use f-string.

    Week 3 Learning Summary

    Week 3 subject 1: Strings (cont.)

    • Modify string literals with embedded values and f-strings.
      • Adding and multiplying strings: note the difference between concatenating strings and printing multiple strings.
    • Methods to format strings

      • .title()
      • .upper(), lower()
      • .lstrip(), rstrip(), strip()
      • .removeprefix()

    • f-strings
      • Use variables in f-strings
      • way to format values of variables into strings
    Week 3 subject 2: Numbers
    • Integer operations
      • +, -, *, /
      • **
      • %, //, pay special attention: how // works for negative numbers!
    • Floating point numbers are numbers with decimal points
    • Floating point operations
      • Same as integers
      • % and // also works for floats!
    • Type conversion from int to float
      • Automatic and manual conversion with float()
    • Never compare if floats are equal!

    25/10/2025

    Week 2 Assignments

    1: Brisbane 2032!

    The 35th Summer Olympics will be held in Brisbane.  The entire city has started preparing.  The Mayor of Brisbane asks you to help, because he hears you know how to draw with Turtle.

    Lord Mayor Adrian Schrinner wants you to help draw an Olympics Symbol like follows.  He said, 'I know you can draw circles like polygons but I also learned that Turtle has a method called circle().  When you draw you can also specify the width of the lines with pensize().  Thank you young programmer!'

    Before you leave you also noticed that the colours of the 5 circles are blue, black, red, yellow and green.

    Write a Python program to draw the symbol as close as possible to the one the Mayor showed you. 



    2: Famous Quotes

    Find a quote from a famous person you admire.  Store both the quote and the name of the person in variables.  Then print the quote and the name of its author.  Your output should look something like the following, including the quotation marks:
     
    Albert Einstein once said, “A person who never made a mistake never tried anything new.” 

    24/10/2025

    Week 2 Learning Summary

     Week 2 subject 1: Comment your code

        # single-line comment

     

    """
    Multi-line
    comments
    for complex 
    topics
    """
    • Add comment at beginning of your code

    Week 2 subject 2: Further Turtle drawing

     
    Week 2 subject 3: Variables

    •  Variables are names for values in memory
    • Use variables to enable your programs to do arbitrary jobs
    • Name rules for variables

    Week 2 subject 4: Python error messages

     

    Week 2 subject 5: Strings

    • String is a Python built-in data type.
    • There are string variables and string literals.
    • string literals are a sequence of characters between a pair of quotation marks.
    • Use of different quotation marks: 
      • escape sequences, 
      • triple quotes for multi-line string literals and,
      • mixed quotation marks.

    17/10/2025

    Week 1 Assignments

    1: Install Python again

    On you computer, uninstall Python.  Make sure you can no longer find python.exe, py.exe or IDLE.  Then step by step, install Python again.  Launch Python to run your program to make sure you know exactly what to do.

    2: Hello everyone

     Modify your 'Hello, world' program to say hello to a number of your best friends.

      3: Turtle gets a new job

      Turtle is known for drawing things on the ground, especially those he can draw without leaving the ground, like a rectangle or a star.  NASA approaches Turtle for a job to draw huge numbers on the earth that the astronauts in the ISS can see.  This would require drawing in outline fonts, which you happen to know how to do.

      Please write a Python program with Turtle to draw outline font numbers 0 - 9:







        Week 1 Learning Summary

        Week 1 subject 1: Installing Python

        • Download the latest version
        • Run installer
        • Be sure to tick 'Add Path'
        • Run IDLE

        Week 1 subject 2: Save you program

        • IDLE -> 'File' -> 'New'
        • Write your code
        • 'File' -> 'Save'
        • Save to the Shared OneDrive -> 'Classes' (or your local drive)
        • 'Run' -> 'Run Module'

          Week 1 subject 3: Draw with Turtle

          • 'from turtle import *' at the beginning of program,
          • fd() / forward()
          • bk() / backward()
          • lt()  / left()
          • rt() / right(),
          • pu() / penup(),
          • pd() / pendown(),
          • pencolor()