Linked Lists

In Python we use lists rather arrays. Although, for our purpose they are one in the same. A node (element) in a linked list contains two fields:

  • Data (of any data type)
  • A pointer that points to the next element in the list
  • We could introduce a ‘previous’ field into the node but we shall just focus on the fore-mentioned fields.

    Also, we must keep track of the size of the list and a pointer that holds the position of the beginning of the list.

    Further reading:

  • Wikipedia – linked lists
  • Tutorials – linked lists
  • We shall build

    What we should know?

    From Higher we should be comfortable with the following:

    What we are going to learn (Software Development):

    Data Structures

    Complex Standard Algorithms

    • Sorting Algorithms
    • Binary Search Algorithm
    • Reading and Writing to a Database

    Object Oriented Programming

    What we are going to learn (Information Systems):

    Deisign Methodololgies

    • Data Dictionary
    • Wire Framing
    • Iterative Programming

    Web Authoring

    • Interactive User Interface
    • Database Driven
    • Mulitple Database Operations

    The Project

    Task 3 – Text Based Adventure Game

    For this task you are required to use all of the skills that you have acquired to construct a text based adventure game. The idea behind a tba game is that the user should be asked  questions and depending on their response, something will happen. You have to let the user know where they are and where they can go. Some of the rooms will contain an item such as a key, treasure or a person.

    Criteria:

    • Use a list to create 4 rooms that can be explored.
    • You will have to use a series of if statements to determine where the user can move and if they pick up an item.
    • All items should be stored in a list.
    • There must be a way of completing your game. You can decide how.
    • I have tried to keep this as open as possible so you can design and implement your way.

    Good luck and quest well!

    Download the starter template.

     

    Task 2 – Loops and Lists

    The use of loops in any programming language improves how efficient the program is and reduces the length of the program. Understanding loops is essential in being able to program and creating useful programs/games. The following information will show what loops are and the different types of loops, why we use them and how to include them within your program.

    When using loops in Python, I think that it is handy to know about Lists. So please work through the following section of codecademy:

    Please read sections 7.1 to 7.5 from the following link: Lists

    – Unit 5: Lists and Dictionaries (only complete the subsection: Lists)
    NOTE: we will not be covering functions.

    Please read sections 4.1 and 4.2 from the following link: For loops

    Now complete the following sections on Codecademy:
    – Unit 8: Loops (only complete the subsection: For Loops).

    You have now dealt with For Loops and should understand that they are referred to as ‘unconditional loops’. You are now going to look at While Loops.

    Please read sections 4.3 and 4.4 from the following link: While loops

    Now complete the following sections on Codecademy:
    – Unit 8: Loops (only complete the subsection: While Loops).

    Display a given message

    Ask the user for a message and then display the message four times

    Password Generator

    You program should generate three random passwords. They should be saved in a list and then displayed to the user.
    Note: The code for creating a random password can seen below:

    >>> import string
    >>> import random
    >>> def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
    ...    return ''.join(random.choice(chars) for _ in range(size))
    ...

     

    Task 1 – Becoming familiar and a bit more!

    In order to complete these series of mini-tasks you will first need to complete sections 1, 2, 3, 4 and 5.

    Read the following links too:
    Quiz games and if statements.

    1: Play withing Strings.
    – The user of your program should enter their first name, surname and date of birth.
    – The program should then display the length of each piece of data and convert it to uppercase and lowercase.

    2: You must create a speed, distance and time calculator.

    Help on creating a calculator can be found here.

    – The user must first choose whether they want to calculate S, D or T.
    – The user should then be prompted to enter in the relevant information for the chosen calculation.
    – The program should then calculate the answer and display an appropriate message. You must use the technique from ‘Strings and Console Ouput – sub-section 15’.
    – Your program should be timestamped (dd/mm/yyyy : hh-mm-ss).

    3. Complete the above problem in Scratch!!!

    3: A Mathematical Calculator (CHALLENGE)
     – You must create a calculator that can perform the basic operations, powers and roots (square) and percentages.

    Code Academy

    We will be using Code Academy to help us learn how to use Python.

    It works by you completing programs via a web browser and the system will provide instant feedback on your solution. Remember, keep your wits about you as some of th problems and concepts can be quite complex.

    Click on the link below to access the Code Academy:

    http://www.codecademy.com/tracks/python

    As a quick reference you can also visit the following site:

    http://www.tutorialspoint.com/python/index.htm

    Getting Started – Python

    At Dunblane High School our main programming language will be Python and this will be used at National 5 and Higher.

    A Bit of History
    Python is a general-purpose interpreted, interactive, object-oriented and high-level programming language. Python was created by Guido van Rossum in the late eighties and early nineties. Like Perl, Python source code is also now available under the GNU General Public License (GPL). Although, Python is quite an old programming language it is making a comeback through its inclusion within the Raspberry Pi software bundle. Development is also in place to convert programs written in Python to apps for Android.