PYTHON PROGRAMMING EXERCISES FOR KEY STAGE 3 AND 4

Liverpool University, Department of Computer Science

Frans Coenen

Created: Tuesday 9 April 2013

Last Updated:



This www page presents a set of programming exercises, and sample solutions, for (UK) key stages 3 and 4 student. Each problem comprises (for download): (i) a .pdf file presenting the problem and a suggested solution and (ii) an executable .py file. The material (except where otherwise indicated) is the copyright of the University of Liverpool. The material is made available for free for non-commercial use, however I woud appreciate appropriate acknowledgement. Should you choose to make use of any of the material for teaching purposes we would greatly appreciate appropriate acknowledgement. The problems are categorised as follows:

  1. Sequence: Simple programming problems that use sequences of commands.
  2. Selection: Programme example problems that involve selection using "if-else" or "elif" statements.
  3. Repetition: Programme examples that involve repetition using "while loops".
  4. Importing Modules: Examples that make use of existing Python modules (in some cases user defined).
  5. Lists and Dictionaries: Examples using the Python list and dictionary structures.
  6. File Handling: Examples that involve file input and file output.

Under eaqch category problems are ordewred according to perceived difficulty.

#Problem Description/Notes .pdf .py
Sequence
1Giant LettersFirst Python Program, sequence of function calls utilising no input and only simple print string output statements. giantLetters2013-3-27.pdf giantLetters.py
2Compound InterestSimple Python that features some arithmetic and formatted output. compoundInterest2013-6-7.pdf compoundInterest.py
3Lower to Upper Case Character ConversionSimple sequential programme that illustratews the concept of The ASCII code, and makes use of the ord() and chr() built in functions. lower2upperCase2013-4-9.pdf lower2upperCase.py
4Swimming PoolTime to fill swimming pool. Constants, integer input (int(raw_input())), formatted output, use of simple arithmetic operators. swimmingPool2013-3-27.pdf swimmingPool.py
5Floating BargeDetermine draft of a barge given given LxBxH. Constants, float input (float(raw_input())), formatted output, use of simple arithmetic operators. floatingBarge2013-3-17.pdf floatingBarge.py
6Landscape Gardening Quote IMore sophisticate large scale problem (based on a AQA GCSE specimen controlled assessment problem) encompassing issues addressed by the above swimming pool and floating barge problems. landsGardQuote_2013-3-28.pdf landsGardQuote.py
Selection
7Power 4Simple "linear if". power4_2013-4-9.pdf power4.py
8Triangle RecognitionNested "if-else" statements and test to ensure that input describes a realisable triangle. triangles2013-3-30.pdf triangles.py
9Quadrilateral RecognitionSimilar to triangle recognition problem (see above), nested "if-else" statements. quadrilaterals2013-3-30.pdf quadrilaterals.py
10CalculatorSimple calculator program that uses a sequence of "if-else" statements (elif). calculator2013-3-30.pdf calculator.py
Repetition
11ASCII Character setSimple "while" loop with counter (and input error check). asciiCharacterSet2013-3-30.pdf asciiCharacterSet.py
12Menu InputSimple "continuous" loop with counter (and more on ASCII code). menuInput2013-4-5.pdf menuInput.py
Using previously created modules (importing modules)
13PythagorasSimple example using the sqrt function in the math module. pythagoras2013-4-8.pdf pythagorasVerI.py and pythagorasVerII.py
14Circle CalculationCalculate area and circumference of circle given radius. Example using the pi constant from the math module. circleCalculation2013-4-7.pdf circleCalculation.py
15ProjectilesPhysics problem. Example using the trigonometric functions and the radians() function in the math module. projectiles2013-3-27.pdf projectiles.py
16Cosine formulaApplication of the cosine formula. Example using the trigonometric functions and the radians(), degrees() and pow() functions in the math module. cosineFormula2013-3-27.pdf cosineFormula.py
17Geographic DistanceExample importing own module (pythagorasVerII), builds on solution to Pthagoras peoblem (see above). geographicDistance2013-3-27.pdf geographicDistance.py and pythagorasVerII.py
Lists and Dictionaries
18Distance conversionSimple application illustrating the use of lists and/or dictionaries. distanceConversion2013-3-30.pdf distanceConversionVer1.py (lists) and distanceConversionVer2.py (dictionaries)
File Handling
19Materials Costs UpdateLoading data from a text file into a dictionary. Builds on Landscape Gardening Quote I problem (see above) materialCostUpdate_2013-3-28.pdf materialCostUpdate.py and the text file newMaterialCosts.txt
20Landscape Gardening Quote IIBased on a AQA GCSE specimen controlled assessment problem. Combines solutions to Landscape Gardening Quote I and Materials Costs Update problems. landsGardQuoteII_2013-3-28.pdf landsGardQuoteII.py
21Summarisation ReportMore sophisticated example of loading data from several text files into dictionaries. Builds on Landscape Gardening Quote I problem (see above) summarisationReport2013-4-7.pdf summarisationReport.py and the text files: (i) quotesToDateFile.txt, (ii) quoteNumber1.txt, (iii) quoteNumber2.txt, (iv) quoteNumber3.txt, (v) quoteNumber4.txt, (vi) quoteNumber5.txt and (vii) quoteNumber6.txt.
22Landscape Gardening Quote IIIComplete solution to AQA GCSE specimen controlled assessment problem. Extension of solutions to Landscape Gardening Quote II problems Summarisation Report problems. landsGardQuoteIII_2013-4-12.pdf landsGardQuoteIII.py and the text files: (i) quotesToDateFile.txt, (ii) quoteNumber1.txt, (iii) quoteNumber2.txt, (iv) quoteNumber3.txt, (v) quoteNumber4.txt, (vi) quoteNumber5.txt and (vii) quoteNumber6.txt.



Created and maintained by: Frans Coenen.