The University of Western Australia
School of Computer Science and Software Engineering

School of Computer Science and Software Engineering

CITS4406 Problem Solving and Programming

Labsheet 1: Getting Started

This labsheet is a gentle introduction to the CSSE working environment and the Python programming language. Make sure you use this time to familiarise yourself with the programming environment before commencing with the technical aspects of the unit.

Labs and After Hours Access

The computers we will use in this unit are the all-in-one computers found in Labs 2.03 of the CSSE building. We will be using the Mac OS however, Python script will run the same way in Windows and Linux. You will have 24/7 access to these labs provided your security card has been enabled for access.

Once you are enrolled in a CSSE unit, your student card should automatically allow you after-hours access to the CSSE building. If you are having any difficulties accessing the lab, please see an administrative assistant in the reception area (Room 1.31).

After-hours access will commence in the second week of semester. Outside normal working hours, make sure you carry your student card with you at all times.

Check your account

Ensure your account is working correctly by logging on.

The lab 2.03 computers will only have Mac OS, although you can use other operating systems to complete exercises at home.

At the login screen type in your Student Number and Pheme password. Usernames and passwords are case sensitive. If you have trouble logging in, try using bookings for both username and password, and the computer will bring up a web page telling you what to do.

After successfully logging in using your account, launch Internet Explorer from the Start Menu. If you are asked for a proxy enter your University account password. This is only needed for accessing websites external to the University. To do this, you will first need to upgrade your account to a Full Service Account if you haven't already done so - see In the meantime you should be able to hit "Cancel" and close any window that is trying to access an external site.

Navigate your way (via the School's "Current Students" page) to the on-line version of this lab sheet and proceed using the on-line version.


The primary and the fastest way to get help in CITS4406 will be via help4406. Try it out now, by reading and sending messages.

Check help4406 often for useful information about the unit, including about the assessments.

Python and IDLE

The suggested way of using Python with the text in this course is via an "integrated program development environment" called IDLE, documented at IDLE docs. IDLE is available both from the Start Menu, via Programming Software, and from the Applications folder on the desktop. Try the following.

  1. Create a folder CITS4406 in your home folder, and a folder Lab1 inside that where you will store the work that you produce today.
  2. Launch IDLE from the Python folder on the desktop.
  3. Try entering some expressions such as the following. IDLE will evaluate each one and display the result, much like a calculator.
    • 8
    • 8 * 2
    • 8 ** 2
    • 8 / 6
    • 8 // 6
    • 8 % 6
    • 8 / 0
    You can probably guess what most of the operators here do: either way we will discuss them in detail later in the unit.
  4. Select File -> New Window.
  5. Enter the following into the new window. These are Python functions. All symbols and indentation are essential.

    def square(x):
            #returns the square of x
            return x * x

    def fibs(x):
            #prints the first x Fibonacci numbers
            #each number is the sum of the previous two
            a,b = 0,1
            for i in range(x):
                    print("fib(", i, ") = ", a)
                    a,b = b,a+b

  6. Select File -> Save.
  7. Navigate to the folder you created earlier and save the new file as
  8. In the window, select Run -> Run Module. If you get any error messages at this point, you haven't entered the code correctly.
  9. Try entering some expressions such as the following.
    • square(-8)
    • fibs(20)
    You're running Python programs already!

Other Exercises

  1. Use the print operation from above to write a Python function that displays the name of the Python course. 

  2. chilli (Challenge) Write a Python function that displays the expressions and answers to Question 3 above.

  3. From page 10 of the text, copy the chaos program (printed below for your convenience) into your 

    def main():
        print("This program illustrates a chaotic function")
        x = eval(input("Enter a number between 0 and 1: "))
        for i in range(1,10):
            x = 3.9 * x * (1 - x)

Run this program and try it with different input values. Select Run -> Run Module.

(a) Modify the program using 2.0 in place of 3.9 in the expression.
(b) Modify the program so that it prints 20 values instead of 10.
(c) Modify the program so that it asks the user for the number of values to print.
(d)  Modify the prograll so that it only prints the final value of x. Change it back again so it prints all values for the next task.
(e) chilliModify the program so that it asks the user for two values of x and then prints two outputs side by side as shown in Section 1.8 of the text (page 15).

What are we learning?

As an indication of what you will be able to achieve in CITS1401, have a look at the prize-winning entries for Project 2 from the last two years. Both years the challenge was to design a board game where the computer plays agains a human. Writing a program where the computer makes legal moves and does not allow the human to make any illegal move would fetch full marks. 

However, an extra component for brilliant students was to put some intelligence into the program where the computer plays good moves and tries to win the game.

Feel free to have a look at these programs from previous years. I am sure they will appear complicated at first but in three months time, if you work hard, you will be able to write something like this!