Python tasks
Every task in one place. Pick a mode, a topic or a concept to practise.
Programming tasks with tests, from easier to demanding.
135 tasks
- Write a programBasicThree lines with one printProgramming basics · Programming challengesPrinting with print()
- Write a programBasicNumbers with dashesProgramming basics · Programming challengesPrinting with print()
- Write a programBasicArea and perimeter of a rectangleVariables and data types · Programming challengesVariables and assignmentNumbers: int and float
- Write a programBasicMinutes to hoursVariables and data types · Programming challengesVariables and assignmentNumbers: int and float
- Write a programBasicSum and average of three numbersInput and output · Programming challengesReading numbers from inputFormatting output: sep, end, f-strings
- Write a programBasicPrice after a discountInput and output · Programming challengesReading numbers from inputFormatting output: sep, end, f-strings
- Write a programBasicTwo numbers reversedInput and output · Programming challengesInput with input()Reading numbers from inputFormatting output: sep, end, f-strings
- Write a programBasicDivisible by 3 and 5Operators · Programming challengesInteger division and remainder: // and %Comparisons: ==, !=, <, >=Logical operators: and, or, not
- Write a programBasicA reduced ticketOperators · Programming challengesComparisons: ==, !=, <, >=Logical operators: and, or, not
- Write a programBasicA grade from a testConditions · Programming challengesComparisons: ==, !=, <, >=Several branches: elif
- Write a programBasicMultiples of a numberLoops · Programming challengesFormatting output: sep, end, f-stringsfor loops and range()
- Write a programBasicAn upside-down pyramidLoops · Programming challengesfor loops and range()
- Write a programBasicFunctions for a rectangleFunctions · Programming challengesDefining and calling functionsParameters and argumentsReturn values: return
- Write a programBasicA word downwards and backwardsStrings · Programming challengesSlicingLooping over a string
- Write a programBasicPositive and negativeLists · Programming challengesCounting and summing in a loopSplitting and joining: split() and join()Looping over a list
- Write a programBasicThe midpoint of a segmentTuples · Programming challengesTuples and immutabilityUnpacking: a, b = …Returning several values
- Write a programBasicA date as a tupleTuples · Programming challengesFormatting output: sep, end, f-stringsSplitting and joining: split() and join()Tuples and immutability
- Write a programBasicAre they all different?Sets · Programming challengeslen, sum, min, max and sortedSets and unique items
- Write a programBasicCommon lettersSets · Programming challengesSplitting and joining: split() and join()Sets and unique itemsUnion, intersection, difference
- Write a programBasicA reversed dictionaryDictionaries · Programming challengesReturn values: returnKeys and valuesLooping over a dictionary: keys, values, items
- Write a programBasicAll occurrencesAlgorithms · Programming challengesReturn values: returnList methods: append, pop, remove, …Linear search
- Write a programBasicSearching a fileWorking with files · Programming challengesReading from a fileThe with statementProcessing a file line by line
- Write a programBasicThe price of an itemExceptions · Programming challengesKeys and valuestry – exceptKinds of exceptions: ValueError, ZeroDivisionError, …
- Write a programBasicThe hypotenuse of a triangleModular programs · Programming challengesImporting modulesStandard modules: math, random
- Write a programBasicFunctions from your own moduleModular programs · Programming challengesImporting modulesYour own modules
- Write a programBasicThe sum from 1 to nRecursion · Programming challengesRecursive functionsThe base case
- Write a programBasicWords reversed with a stackAdvanced data structures · Programming challengesList methods: append, pop, remove, …Stacks and queues
- Write a programBasicCompressing textAlgorithmic problems · Programming challengesLooping over a stringBreaking a problem into stepsEdge cases
- Write a programBasicDigit sumGraduation exam preparation · StringsConverting types: int(), float(), str()Counting and summing in a loopLooping over a string
- Write a programBasicHalf pyramidGraduation exam preparation · StringsInput with input()for loops and range()Slicing
- Write a programBasicFinding a characterGraduation exam preparation · StringsInput with input()String methods: upper, find, replace, …
- Write a programBasicPalindromeGraduation exam preparation · StringsTwo branches: if – elseSlicingString methods: upper, find, replace, …
- Write a programBasicFibonacci into a listGraduation exam preparation · Listsfor loops and range()Creating lists and indexingList methods: append, pop, remove, …
- Write a programBasicA random list reversedGraduation exam preparation · ListsReturn values: returnSlicingLooping over a listStandard modules: math, random
- Write a programBasicSum of even numbersGraduation exam preparation · ListsInteger division and remainder: // and %Counting and summing in a loopReturn values: returnLooping over a list
- Write a programBasicEntered values reversedGraduation exam preparation · ListsReading numbers from inputwhile loopsSlicingList methods: append, pop, remove, …
- Write a programBasicThe largest and the smallest numberGraduation exam preparation · Listswhile loopsList methods: append, pop, remove, …len, sum, min, max and sortedFinding the minimum and maximum
- Write a programBasicGuess the wordGraduation exam preparation · The while loopInput with input()The if statementwhile loopsString methods: upper, find, replace, …
- Write a programBasicNumbers without 3, 7 and 14Graduation exam preparation · The while loopReading numbers from inputLogical operators: and, or, notThe if statementwhile loops
- Write a programBasicEven numbers up to a limitGraduation exam preparation · The while loopReading numbers from inputwhile loops
- Write a programBasicCharacters and their positionsGraduation exam preparation · The while loopInput with input()while loopsIndexing characters
- Write a programBasicCounting down to 5Graduation exam preparation · The while loopReading numbers from inputThe if statementwhile loops
- Write a programBasicOdd numbers except 17Graduation exam preparation · The while loopComparisons: ==, !=, <, >=The if statementwhile loops
- Write a programBasicCoin tossGraduation exam preparation · Mixed tasksfor loops and range()Counting and summing in a loopReturn values: returnStandard modules: math, random
- Write a programBasicTrain passengersGraduation exam preparation · Mixed tasksReading numbers from inputThe if statementwhile loopsCounting and summing in a loop
- Write a programBasicLeap yearGraduation exam preparation · Mixed tasksReading numbers from inputInteger division and remainder: // and %Logical operators: and, or, notTwo branches: if – else
- Write a programBasicA little houseGraduation exam preparation · Graphics with tkinterDrawing on a canvas (tkinter)
- Write a programBasicCircles by clickingGraduation exam preparation · Graphics with tkinterDefining and calling functionsDrawing on a canvas (tkinter)Events: clicks and keys
- Write a programBasicA numeric passwordGraduation exam preparation · Exceptions (try – except)while loopsbreak and continuetry – exceptValidating input
- Write a programElementaryA house made of charactersProgramming basics · Programming challengesPrinting with print()Error messages
- Write a programElementaryMinutes and seconds in a yearProgramming basics · Programming challengesPrograms and how they runPrinting with print()
- Write a programElementaryText and a number in one sentenceVariables and data types · Programming challengesText: the str typeConverting types: int(), float(), str()
- Write a programElementaryAverage speedVariables and data types · Programming challengesVariables and assignmentNumbers: int and floatConverting types: int(), float(), str()
- Write a programElementaryA four-digit number backwardsOperators · Programming challengesArithmetic operatorsInteger division and remainder: // and %
- Write a programElementaryA calculatorConditions · Programming challengesArithmetic operatorsSeveral branches: elifNested conditions
- Write a programElementaryCounting digits without textLoops · Programming challengesInteger division and remainder: // and %while loopsCounting and summing in a loop
- Write a programElementaryThe largest of threeFunctions · Programming challengesSeveral branches: elifParameters and argumentsReturn values: return
- Write a programElementaryA square made of rowsFunctions · Programming challengesfor loops and range()Defining and calling functionsParameters and arguments
- Write a programElementarySURNAME, NameStrings · Programming challengesString methods: upper, find, replace, …Splitting and joining: split() and join()
- Write a programElementaryAlternating lettersStrings · Programming challengesIndexing charactersLooping over a stringString methods: upper, find, replace, …
- Write a programElementaryA list backwards without reverseLists · Programming challengesfor loops and range()Creating lists and indexingLooping over a list
- Write a programElementaryWhere the smallest item isLists · Programming challengesReturn values: returnCreating lists and indexingLooping over a list
- Write a programElementaryThe warmest and the coldest townTuples · Programming challengesLooping over a listTuples and immutabilityUnpacking: a, b = …
- Write a programElementaryA pangramSets · Programming challengesString methods: upper, find, replace, …Sets and unique itemsMembership: in
- Write a programElementaryMissing numbersSets · Programming challengesfor loops and range()Sets and unique itemsUnion, intersection, difference
- Write a programElementaryLetter countsDictionaries · Programming challengesString methods: upper, find, replace, …Looping over a dictionary: keys, values, itemsCounting occurrences
- Write a programElementaryWords by their first letterDictionaries · Programming challengesList methods: append, pop, remove, …Keys and valuesLooping over a dictionary: keys, values, items
- Write a programElementaryMinimum and maximum in one passAlgorithms · Programming challengesLooping over a listReturning several valuesFinding the minimum and maximum
- Write a programElementaryThe best resultWorking with files · Programming challengesFinding the minimum and maximumReading from a fileProcessing a file line by line
- Write a programElementaryNames sorted into a fileWorking with files · Programming challengeslen, sum, min, max and sortedReading from a fileWriting to a fileThe with statement
- Write a programElementaryA safe quotientExceptions · Programming challengestry – exceptKinds of exceptions: ValueError, ZeroDivisionError, …Validating input
- Write a programElementaryChecking the sides of a rectangleExceptions · Programming challengesReturn values: returnKinds of exceptions: ValueError, ZeroDivisionError, …Raising an exception: raise
- Write a programElementaryGrade statistics in functionsModular programs · Programming challengesReturn values: returnlen, sum, min, max and sortedSplitting a program into functions
- Write a programElementaryCounting digits recursivelyRecursion · Programming challengesInteger division and remainder: // and %Recursive functionsThe base case
- Write a programElementaryThe maximum of a list recursivelyRecursion · Programming challengesSlicingThe base caseRecursive algorithms
- Write a programElementaryThe largest item of a matrixAdvanced data structures · Programming challengesNested loopsFinding the minimum and maximumTwo-dimensional lists
- Write a programElementaryThe medianAlgorithmic problems · Programming challengesReturn values: returnSortingEdge cases
- Write a programElementaryA piece on a game boardAlgorithmic problems · Programming challengesbreak and continueMembership: inSimulation
- Write a programElementaryBMI calculatorGraduation exam preparation · StringsReading numbers from inputFormatting output: sep, end, f-stringsArithmetic operatorsSeveral branches: elif
- Write a programElementaryThe Fibonacci sequenceGraduation exam preparation · StringsVariables and assignmentReading numbers from inputfor loops and range()
- Algorithmic problemElementaryGreatest common divisorGraduation exam preparation · StringsInteger division and remainder: // and %while loopsDivisibility, primes, GCD
- Write a programElementaryA number inside a random numberGraduation exam preparation · StringsConverting types: int(), float(), str()Return values: returnString methods: upper, find, replace, …Standard modules: math, random
- Write a programElementaryCaesar cipherGraduation exam preparation · StringsInteger division and remainder: // and %Several branches: elifLooping over a stringCharacters and codes: ord() and chr()
- Write a programElementaryCharacters and wordsGraduation exam preparation · StringsString methods: upper, find, replace, …Splitting and joining: split() and join()len, sum, min, max and sorted
- Write a programElementaryQuadratic equationGraduation exam preparation · StringsReading numbers from inputArithmetic operatorsSeveral branches: elifStandard modules: math, random
- Small projectElementaryRock, paper, scissorsGraduation exam preparation · StringsLogical operators: and, or, notSeveral branches: elifReturn values: returnStandard modules: math, random
- Write a programElementaryPassword checkGraduation exam preparation · StringsLogical operators: and, or, notThe if statementLooping over a stringString methods: upper, find, replace, …
- Write a programElementaryElements that occur only onceGraduation exam preparation · ListsReturn values: returnList methods: append, pop, remove, …Looping over a listStandard modules: math, random
- Write a programElementarySki jumpersGraduation exam preparation · ListsFormatting output: sep, end, f-stringsReturn values: returnLooping over a listlen, sum, min, max and sorted
- Write a programElementaryEven and odd, sortedGraduation exam preparation · ListsInteger division and remainder: // and %while loopsList methods: append, pop, remove, …len, sum, min, max and sorted
- Write a programElementaryThe second largest numberGraduation exam preparation · ListsList methods: append, pop, remove, …len, sum, min, max and sortedSets and unique itemsFinding the minimum and maximum
- Write a programElementaryVowel or consonantGraduation exam preparation · ListsSeveral branches: elifwhile loopsString methods: upper, find, replace, …Membership: in
- Write a programElementaryGuest namesGraduation exam preparation · Listswhile loopsString methods: upper, find, replace, …Splitting and joining: split() and join()List methods: append, pop, remove, …
- Write a programElementaryCommon elements of two listsGraduation exam preparation · ListsReturn values: returnList methods: append, pop, remove, …Looping over a listMembership: in
- Write a programElementaryThe most frequent elementGraduation exam preparation · ListsSplitting and joining: split() and join()List methods: append, pop, remove, …len, sum, min, max and sortedFinding the minimum and maximum
- Write a programElementaryTime in secondsGraduation exam preparation · The while loopReading numbers from inputFormatting output: sep, end, f-stringsInteger division and remainder: // and %while loops
- Algorithmic problemElementaryThe Collatz sequenceGraduation exam preparation · The while loopReading numbers from inputInteger division and remainder: // and %Two branches: if – elsewhile loops
- Algorithmic problemElementaryTo binaryGraduation exam preparation · The while loopText: the str typeReading numbers from inputInteger division and remainder: // and %while loops
- Write a programElementaryLotteryGraduation exam preparation · Mixed taskswhile loopsReturn values: returnList methods: append, pop, remove, …Standard modules: math, random
- Write a programElementaryPrime numbersGraduation exam preparation · Mixed tasksInteger division and remainder: // and %while loopsReturn values: returnDivisibility, primes, GCD
- Write a programElementaryMinimum, count and positionsGraduation exam preparation · Mixed tasksReturn values: returnLooping over a listlen, sum, min, max and sortedFinding the minimum and maximum
- Write a programElementaryTest scoresGraduation exam preparation · Mixed tasksFormatting output: sep, end, f-stringswhile loopsList methods: append, pop, remove, …len, sum, min, max and sortedtry – except
- Write a programElementaryPerfect numbersGraduation exam preparation · Mixed tasksInteger division and remainder: // and %for loops and range()Return values: returnDivisibility, primes, GCD
- Small projectElementaryA tuft of grassGraduation exam preparation · Graphics with tkinterfor loops and range()Standard modules: math, randomDrawing on a canvas (tkinter)Events: clicks and keys
- Write a programElementaryA colour-changing squareGraduation exam preparation · Graphics with tkinterDefining and calling functionsStandard modules: math, randomDrawing on a canvas (tkinter)Animation: after()
- Write a programElementaryA text windmillGraduation exam preparation · Graphics with tkinterInput with input()for loops and range()Drawing on a canvas (tkinter)
- Small projectElementaryA row of squaresGraduation exam preparation · Graphics with tkinterfor loops and range()Drawing on a canvas (tkinter)Animation: after()
- Write a programElementaryColoured raysGraduation exam preparation · Graphics with tkinterSeveral branches: elifDefining and calling functionsDrawing on a canvas (tkinter)Events: clicks and keys
- Small projectElementaryGuess a number from 1 to 50Graduation exam preparation · Exceptions (try – except)Several branches: elifwhile loopstry – exceptValidating inputStandard modules: math, random
- Write a programElementaryA bounded Fibonacci sequenceGraduation exam preparation · Exceptions (try – except)Reading numbers from inputwhile loopsList methods: append, pop, remove, …try – except
- Write a programElementaryIs the number divisible?Graduation exam preparation · Exceptions (try – except)Integer division and remainder: // and %Splitting and joining: split() and join()try – exceptKinds of exceptions: ValueError, ZeroDivisionError, …
- Write a programElementaryA safe averageGraduation exam preparation · Exceptions (try – except)while loopslen, sum, min, max and sortedtry – exceptKinds of exceptions: ValueError, ZeroDivisionError, …
- Write a programIntermediateA price tableInput and output · Programming challengesReading numbers from inputFormatting output: sep, end, f-strings
- Write a programIntermediateThe time a few minutes laterOperators · Programming challengesFormatting output: sep, end, f-stringsArithmetic operatorsInteger division and remainder: // and %
- Write a programIntermediateThree numbers from the smallestConditions · Programming challengesVariables and assignmentThe if statementNested conditions
- Write a programIntermediateParking feeConditions · Programming challengesFormatting output: sep, end, f-stringsInteger division and remainder: // and %Two branches: if – elseSeveral branches: elif
- Write a programIntermediateThe largest before a negativeLoops · Programming challengeswhile loopsCounting and summing in a loopbreak and continue
- Write a programIntermediateThe least common multipleFunctions · Programming challengeswhile loopsDefining and calling functionsReturn values: return
- Write a programIntermediateA number with spacesStrings · Programming challengeswhile loopsSlicingLooping over a string
- Write a programIntermediateShifting by k placesLists · Programming challengesReturn values: returnSlicingCreating lists and indexing
- Write a programIntermediateA rectangle around pointsTuples · Programming challengesUnpacking: a, b = …Returning several valuesFinding the minimum and maximum
- Write a programIntermediateTotal points and rankingDictionaries · Programming challengeslen, sum, min, max and sortedTuples and immutabilityLooping over a dictionary: keys, values, itemsCounting occurrences
- Write a programIntermediateBubble sort, descendingAlgorithms · Programming challengesNested loopsCreating lists and indexingSorting
- Write a programIntermediateConverting to a baseAlgorithms · Programming challengesInteger division and remainder: // and %while loopsDivisibility, primes, GCD
- Write a programIntermediateThe three most common wordsWorking with files · Programming challengesTuples and immutabilityCounting occurrencesReading from a file
- Write a programIntermediateReading a decimal numberExceptions · Programming challengeswhile loopsString methods: upper, find, replace, …try – exceptValidating input
- Write a programIntermediateEstimating π by chanceModular programs · Programming challengesCounting and summing in a loopReturn values: returnStandard modules: math, random
- Write a programIntermediateAll words from the letters a, b, cRecursion · Programming challengesList methods: append, pop, remove, …How recursion unfoldsRecursive algorithms
- Write a programIntermediateAverage points per classAdvanced data structures · Programming challengeslen, sum, min, max and sortedLooping over a dictionary: keys, values, itemsLists of dictionaries and nested structures
- Write a programIntermediateHot potatoAdvanced data structures · Programming challengeswhile loopsStacks and queues
- Write a programIntermediateCounting pairs with a sum - fastAlgorithmic problems · Programming challengesReturn values: returnCounting occurrencesEfficiency of a solution
- Small projectIntermediateBirth numberGraduation exam preparation · StringsConverting types: int(), float(), str()Integer division and remainder: // and %The if statementSlicingString methods: upper, find, replace, …
- Write a programIntermediateMind readerGraduation exam preparation · StringsReading numbers from inputInteger division and remainder: // and %while loopsReturn values: returntry – except
- Small projectIntermediateShopping basketGraduation exam preparation · ListsFormatting output: sep, end, f-stringswhile loopsList methods: append, pop, remove, …len, sum, min, max and sorted
- Small projectIntermediateScreensaverGraduation exam preparation · Graphics with tkinterStandard modules: math, randomDrawing on a canvas (tkinter)Animation: after()Buttons and entry fields