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
- 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.
- 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.
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.
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.
- Improve 1D List exercise 1 using a bubble sort so that the list is displayed in alphabetical order.
- 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.
- 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
- 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
- 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!.
- 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.
- 1. Introduction to Python
- 2. Data types and Operators
- 3. String Operation and Math Unit Exercises
- 4. The IF Statement
- 5. More on IF
- 6. The Maze Game
- 7. Selection Exercises
- 8. FOR Loops
- 9. While Loops
- 10. Making a quiz
- 11. Iteration Exercises
- 12. Lists, Functions and Files
- 13. Creating a list
- 14. Lists with a FOR Loop
- 15. List operations
- 16. Consolidation
- 17. Lists Exercises
- 18. Functions
- 19. Parameters
- 20. Functions with parameters
- 21. Menu Program
- 22. Functions Exercises
- 23. Reading from a file
- 24. Reading from a file - Part 2
- 25. Writing to a file
- 26. Extending the Quiz