Official Frontpage of this assessment

Coursework Part 1

1.1) Write Python/SymPy code that solves the following logic puzzle.

A student is trying to determine which modules to study in the next semester.

  • Physics has maths as a prerequisite.
  • Chemistry is taught at the same time as introduction to computing.
  • The student already took biology last year.
  • The student must take at least one natural science: physics or chemistry or biology.
  • The student has not previously taken maths.
  • The student absolutely hates chemistry.

    1.2) Write Python/SymPy code that implements a recursive function according to the following description:

    The Kaprekar-number:

    The Indian mathematician Kaprekar discovered that if you take a 4 digit number (for example 1746) and sort it a) so that the digits decrease (7641) and b) so that the digits increase (1467) and then subtract these two numbers (7641 - 1467) the result is often 6174. If the result is not 6174, one repeats the sorting and subtraction with the result. After at most 7 steps the result will be 6174. For example:

    1. step: 7652-2567=5085
    2. step: 8550-0558=7992
    3. step: 9972-2799=7173
    4. step: 7731-1377=6354
    5. step: 6543-3456=3087
    6. step: 8730-0378=8352
    7. step: 8532-2358=6174

    Implement this as a recursive function.


  • You can sort a list using [a,b,c,d] = sorted([a,b,c,d]).
  • str(n) turns a number into a string
  • int(n) turns a string into a number
  • list() turns a string into a list, for example: list("word") returns ['w', 'o', 'r', 'd']

    Coursework Part 2

    2.1) Data analysis: download these two files: modules.csv and prereq.csv and analyse them as described below.
    (The module.csv file contains modules and their grouping into subject groups: CSN (computer systems and networks), SET (software engineering technology), INF (information systems), IMD (interactive media design) which all belong to SOC (school of computing). The prereq.csv file contains prerequisite information. The module on the left is a prerequisite for the module on the right.)

    2.1.1) Using Excel, calculate measures of central tendency (mode, median, arithmetic mean, geometric mean) and of dispersion (variance, standard deviation) for the modules.csv data. The data may require some preprocessing, e.g. calculation of frequencies, first. Calculate only those measures that are appropriate and meaningful for the type of data. Also, produce a chart (diagram) of the data. For your answer, provide the values and print the chart. Write a couple of sentences explaining why certain measures are meaningful or not meaningful for this data.

    2.1.2) Using NetworkX, calculate the PageRanks for both data sets and determine whether any of the two data sets is a small-world network. Your answer should include the code; the nodes with the highest PageRank and an answer to the question about small-world networks.

    2.1.3) Produce a gif file for the non-bipartite graph using NetworkX and a concept lattice for the bipartite graph using ConExp. Choose a good layout for the gif file and make sure that there are not any overlapping nodes/labels in the concept lattice. Print the pictures and write a couple of sentences explaining/analysing the graphs.

    Coursework: Challenge

    This challenge is optional (and more difficult). You can pass the coursework without attempting the challenge, but you will get a higher mark if you attempt the challenge. You will get some points for partial solutions, pseudocode or a verbal description of an algorithm for this challenge.

    Challenge: the average clustering coefficient used for determining small-world networks is not meaningful for bipartite graphs (why?). Write a Python script which calculates a clustering coefficient for bipartite networks that is at least somewhat meaningful. Test your script on the data from Part 2.

    A basic solution for this problem can be developed with what you learned in this class and with looking for suitable functions in NetworkX. You should not need to use materials from the web for this, but you are allowed to use web materials if you want. If you are using web materials, you must include a list of URLs of the materials that you used.

    How to submit your work/Deadlines

    Code hand-in: Monday in Week 12, March 28, 15:00: Coursework demos: in addition to handing in the printed code, you also need to show your code to the module leader. You can demonstrate your code during any practical before the deadlines given below. For the demonstration, you only need to show that you have implemented something which runs without errors and produces a result. This should only take a few minutes.

    Asking for help and Safeguarding your work

    You are NOT allowed to post questions relating to the coursework on the internet or discuss the coursework with other people. If you need help you may ask the module leader during the practicals, in particular if you have problems getting started or cannot understand some aspect of this coursework.

    You should change the permission of your files on the server (by using chmod 600 filename) so that others can't read them.

    Deadline Extensions

    Module leaders are not allowed to give extensions. Losing your code because you didn't make backups or having problems with the Napier server are not reasons for extensions.

    If you have mitigating circumstances, you should discuss this with your Programme Leader who might give you an extension. But extensions of more than 2 weeks are not accepted by the module leader, even if your Programme Leader signs this. If you have severe mitigating circumstances then you must go through the official mitigating circumstances process and submit your coursework at the resit diet.

    Marking Scheme

    If you submit your coursework late (up to 5 working days after the deadline), the mark will be capped at 40%. After that your coursework will be marked as "fail".

    You can reach a total of 50 points for the coursework. This is 100% of your final mark. The points will be distributed as follows:

    1.1 logic10 points
    1.2 recursive function10 points
    2.1.1 statistical measures7 points
    2.1.2 PageRank/small-world7 points
    2.1.3 pictures6 points
    Challenge10 points