Lists Exercises

On this page you will find a range of additional exercises that will help you practice lists. Some of these exercises will be quite challenging if you are new to programming.

There are various hints and demonstrations on this page to help you - be sure to read over them carefully. You may also need to investigate the Python Documentation.

You will find the solutions to these exercises on your GitHub page.


1D List Exercises

  1. Create a program that will keep track of items for a shopping list. The program should keep asking for new items until nothing is entered (no input followed by enter/return key). The program should then display the full shopping list.
  2. Write a program that will store the schedule for a given day for a particular TV station. The program should ask you for the name of the station and the day of the week before asking you for the name of each show and the start and stop times. Once the schedule is complete it should be displayed as a table.
  3. Create another version of the Hangman game, this time using Lists. The program should ask for the word to guess and the number of chances to be given.

    It should then split the characters in the word into individual items in a list. The other player should then be allowed to guess characters in the word. The program should display correctly guessed characters and unknown characters in the same way as the previous Hangman game.


Bubble Sort

A Bubble Sort is a simple algorithm that you can use to sort a list into alphabetical order. It can be expressed in psuedo-code as:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
noMoreSwaps ← FALSE
    WHILE noMoreSwaps = FALSE DO
        noMoreSwaps ← TRUE
        FOR element IN 0 TO ((LENGTH of listOfItems) - 1) DO
            IF listOfItems[element] > listOfItems[element + 1] THEN
                noMoreSwaps ← FALSE
                temp ← listOfItems[element]
                listOfItems[element] ← listOfItems[element+1]
                listOfItems[element+1] ← temp
            END IF
        END FOR
    END WHILE

This bubble sort algorithm is based on one provided for the A-Level Computing specification. There are also far more efficient algorithms for this purpose but knowledge of bubble sort is a requirement at A-Level.


Improvement Exercises

  1. Improve 1D List exercise 1 using a bubble sort so that the list is displayed in alphabetical order.
  2. Improve 1D List exercise 2 using a 2D List i.e. each show should have its own list containing the name of the show, start time and stop time.


Quiz

  1. Create a program that will enable you to create and store quiz questions with multiple choice answers and then allow someone else to take the quiz.


List and Menu

  1. Improve Improvement exercise 1 so that you are presented with a menu enabling you to either add items to the list, sort the list, display the list, delete the list or exit the program.


(Hopefully) Very Challenging Exercises

  1. Create a game of Connect 4 for two players. Assume that there can only be vertical and horizontal wins. Diagonals are not allow for the moment. Ignore any validation of moves - assume no cheating!.
  2. You have been given some code for a text based first person shooter game. Using the example code and your current knowledge, complete the program.