Functions Exercises

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

All of these exercises are based on exercise from the previous sections. If you have not completed some of these exercises the solution for the previous exercise has been provided.

In some of the later exercises you should consider how you could generalise any functions you need to create.


Task 3

Refactoring Iteration Exercises

  1. Basic Exercise 2 asked you to create a program which will produce times tables. Refactor this program to use functions.
  2. Challenging Exercise 1 asked you to use a linear search to locate a given character in a text string. Refactor this program to use functions.
  3. Very Challenging Exercise 3 asked you to create a program to convert from hexadecimal to decimal. Refactor this program to use functions.

Task 4

Refactoring Lists Exercises

  1. 1D List Exercise 1 asked to keep track of a shopping list. Refactor this program to use functions.
  2. 1D List Exercise 3 asked you to create a version of Hangman. Refactor this program to use functions.
  3. Improvement Exercise 1 asked you to improve the shopping list program with a bubble sort. Refactor this program to use functions.
  4. List and Menu Exercise 1 asked you to create a menu based interface for your shopping list program. Refactor this program to use functions.
  5. Very Challenging Exercise 1 asked you to create a version of Connect 4. Refactor this program to use functions.
  6. Very Challenging Exercise 2 asked you to create a basic text based first person shooter game. Refactor this program to use functions.