Python For GCSE
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.
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.
Write a subroutine which accepts a list as a parameter. The subroutine should print the first and last items in the list.
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.
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]
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).
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.
Write functions to convert values in centimetres into feet and inches. Write another function to convert inches to centimetres.
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.
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.
Write a function to sum the digits of a number.
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.
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.
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.
Write a function that accepts a list of integers but returns a new list of only the positive integers.
Write a function that pads out a string with leading zeroes.
You might use this function to create binary strings of a specified length.
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.
Write a program to output every permutation of the five vowels, each one including all 5 vowels only once.
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.
Write a Python program to create all possible permutations from a given list of different numbers.
Using bitwise operators only, work out how to add two numbers together.
Write a function that accepts 3 integer parameters. The function should return the median of those three numbers.
Write a function that works out whether a number has an odd or even number of factors.
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.
Write a function that duplicates all elements of a string. For example, given the string, mouse, the function should return mmoouussee.
Write a function that accepts a list as a parameter and returns a new list with duplicate values removed.
Write a program to generate a list of 10 unique, even numbers between 0 and 100.
Write a function that checks if a given string contains any duplicate letters.
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.
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).
Write a function that accepts a list of integers. It should return the largest sum of adjacent numbers found in the list.
Write a function that accepts a list of integers. It should return the largest product of adjacent numbers found in the list.
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.
Write a function called Devowel which accepts a string and returns a new string with all of the vowels removed.
Write a function which accepts a string and returns a new string which alternates the case (upper and lower) of each letter.
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.
Write functions to convert between the RGB and hexadecimal representations of colours.
Write a function that accepts a list of lists of integers. The program should flatten the lists to make a single list of integers.
Write a function that accepts a string. The function should return a new string where each word of the original has its order scrambled.
Write a function to determine the mode of a list of numbers.