# Python For GCSE

Extra Tasks

## Introduction

This page has an odd assortment of tasks and challenges to work on towards the end of your GCSE course to keep practising your programming. Some of them are easy, some hard.

### Task 1

Write a program to accept a filename from the user. Separate the input into two parts, the name of the file and its extension. Print both.

Then write a function which accepts a filename as a parameter. The function should return the extension.

### Task 2

Write a subroutine which accepts a list as a parameter. The subroutine should print the first and last items in the list.

### Task 3

Write a function that accepts a first number (a), a second number (b) and a third number (c). The function should return true if **a** is within **c** of **b**.

### Task 4

Write a program that prints only the even numbers from the following list.

nums = [911, 490, 967, 673, 251, 904, 419, 915, 196, 869, 738, 221, 959, 441, 177, 608, 187, 813, 537, 360]

### Task 5

Write a function with the parameters a, b, c and d. The function should return the distance between the coordinates (a,b) and (c,d).

### Task 6

Write a function that returns the sum of the first n integers. Write two further functions to sum the first n odd and the first n even numbers.

### Task 7

Write functions to convert values in centimetres into feet and inches. Write another function to convert inches to centimetres.

### Task 8

Write a function to convert hours, minutes and seconds into a total number of seconds. Write another function to convert a total number of seconds to hours, minutes and seconds.

### Task 9

Write a program in which a user enters their height in metres and their mass in kilograms. The program should calculate the user's BMI by dividing the mass in kilograms by the square of the height.

### Task 10

Write a function to sum the digits of a number.

### Task 11

Write a program in which a user enters two sets of coordinates. The program should calculate and output the coordinates of the midpoint of the line.

### Task 12

Write a function that accepts a name as a parameter. The program should convert the name to uppercase and sum the ASCII values of the letter characters in the name. It should then divide by the number of letters. The result should be rounded to the nearest integer and then converted into a character. This value is the mean letter in the name and should be returned by the function.

### Task 13

Write a program that defines a list of names. The program should find the mean character score (as a float) of the letters of each name converted to upper case. The program should output the names, the mean letter scores and should work out the name with the best mean score.

### Task 14

Write a function that accepts a list of integers but returns a new list of only the positive integers.

### Task 15

Write a function that pads out a string with leading zeroes.

You might use this function to create binary strings of a specified length.

### Task 16

Write a program in which a user enters two integers (separated by a comma). You can integrate this with code that treats these numbers as coordinates.

### Task 17

Write a program to output every permutation of the five vowels, each one including all 5 vowels only once.

### Task 18

Write a Python program to remove and print every third number from a list of numbers until the list becomes empty. Look up a definition of the Josephus problem and then use your program to explore the problem.

### Task 19

Write a Python program to create all possible permutations from a given list of different numbers.

### Task 20

Using bitwise operators only, work out how to add two numbers together.

### Task 21

Write a function that accepts 3 integer parameters. The function should return the median of those three numbers.

### Task 22

Write a function that works out whether a number has an odd or even number of factors.

### Task 23

Write a function which accepts 4 pairs of coordinates defining two lines. The function should return a boolean value indicating whether or not the lines are parallel.

### Task 24

Write a function that duplicates all elements of a string. For example, given the string, **mouse**, the function should return **mmoouussee**.

### Task 25

Write a function that accepts a list as a parameter and returns a new list with duplicate values removed.

### Task 26

Write a program to generate a list of 10 unique, even numbers between 0 and 100.

### Task 27

Write a function that checks if a given string contains any duplicate letters.

### Task 28

Write a function that accepts two strings as parameters. It should return true if the second string can be made using letters from the first.

### Task 29

Write a function that accepts a list of integers as a parameter. The function should return a new list containing cumulative totals of the numbers in the list (a running total).

### Task 30

Write a function that accepts a list of integers. It should return the largest sum of adjacent numbers found in the list.

### Task 31

Write a function that accepts a list of integers. It should return the largest product of adjacent numbers found in the list.

### Task 32

Two circles will touch if the distance between their centres, d , is equal to the sum of their radii, or the difference between their radii. Write a function that accepts the coordinates of the centres and radii of two circles and determines if they intersect.

### Task 33

Write a function called **Devowel** which accepts a string and returns a new string with all of the vowels removed.

### Task 34

Write a function which accepts a string and returns a new string which alternates the case (upper and lower) of each letter.

### Task 35

Write a program that accepts a string of text. The program should make a list of the unique words in the string and a count of the occurrences of each of those unique words.

### Task 36

Write functions to convert between the RGB and hexadecimal representations of colours.

### Task 37

Write a function that accepts a list of lists of integers. The program should flatten the lists to make a single list of integers.

### Task 38

Write a function that accepts a string. The function should return a new string where each word of the original has its order scrambled.

### Task 39

Write a function to determine the mode of a list of numbers.