Python Resource Pack 6
Python Resource Pack 6 is a set of coding challenges designed to support the teaching and learning of the Python programming language.
This pack is designed for those who have some experience of programming in Python, such as completing the exercises in Resource Packs 1 - 5. It is suitable for teaching Python in schools at GCSE, AS and A Level, for tutors and learners in adult learning classes or for the hobbyist learning at home.
As part of the higher-level learning and exam preparation for which the pack is designed, emphasis is placed on the system life cycle and program documentation by requiring:
- Preparatory design before attempting to code the solution to the challenge.
- Full validation to prevent the wrong type of data or incorrect values from being entered.
- The use of meaningful names for variables, functions and procedures.
- Fully commenting code.
- Full testing (both unsuccessful and successful tests, together with any corrective actions) to be recorded as a part of the solution alongside the code.
The pack is designed to support learning that has previously taken place in the classroom, via self-directed study, or by following tutorials.
The pack contains eleven challenges, each consisting of:
- A pdf file with one or more coding challenges and, in some cases, supplementary extension work.
- Fully commented example solutions to the challenge or challenges and any extensions.
The following topics are introduced:
- Writing recursive as opposed to iterative solutions.
- The
global
command to create static variables. - The
round
command to round numbers to a given degree of accuracy. - The use of
end=
in print commands. - The
%
mathematical operator to perform modulo division. - The
.append()
command with lists. - The
**
function for calculating exponents; - The
math
module; - The import math command.
- The
math.degrees()
command to convert from radians to degrees. - The
math.asin()
command (the equivalent of sin-1). - The
math.pi()
command representing π. - The
math.sin()
command. - The
math.cos()
command. - The
in
command for checking if an item is in a list. - The
pass
command in error trapping. - The
match… case
command to make selections based on the value of a variable. - The
not in
command to search for strings within strings. - The use of constants and a constants file.
The challenges are designed so that self-directed research will be required to complete them; they are not a cut-and-paste tutorial.
The challenges:
- Input an integer and calculate its factorial. Includes extension work.
- Fahrenheit to Celsius / Celsius to Fahrenheit temperature converter, taking into account Absolute Zero.
- Huffman Code generator.
- Input an integer and display the Fibonacci Sequence up to that integer. Includes extension work.
- Enter a purchase price and profit percentage, then show the sale price applying mark-up and margin.
- Input a positive integer and display whether it is a Perfect Number or not. If it is, list its other factors.
- Four coding problems inspired by the work of Isambard Kingdom Brunel.
- Input three positive integers representing Vertices, Faces and Edges and state if they represent a Platonic Solid or not. Includes extension work calculating other facts about the solid if it is Platonic.
- Input a positive integer and state whether it is a Happy Number or not.
- Apply a set of rules to a string representing a freight train, and state if it is valid or not. If it is not, explain all the reasons why it is invalid. Includes extension work.
- Write a counting game according to the given rules and using a supplied constants file. Includes extension work.