Programming Puzzles

Updated on 28 Dec 2022

Programming isn’t just about code and syntax. It’s more about solving problems, and invariably using the right tools for the right job. Although you have learnt some Python, the following will require combining problem solving skills with Python to come up with a solution.

middle of the road

I want a solution that will give me the middle of the string. I.e. Brent will yield e and Mark will yield ar.

concrete

I want to create concrete pylons. First I need to figure out the formula for the volume of a circular tube. Once I have supplied the variables (or locked some in, i.e. fixed height or radius) I need to make sure that the answer is rounded up to the nearest whole number.

As a bonus you could adjust it to work out how many concrete trucks you require. Assume they hold 9 cubic metres of concrete and you can only order whole trucks.

long strings

Some strings (titles) might be too long for what I require. The string should be no longer than 40 characters. If it is, I want it chopped down and ... added to the end so that it is no more than 40 characters in length. Also I want my chopped down version to only have whole words.

dates

I want a script that when run will output something similar to this:

good morning, today is Thursday

Where python works out if it is morning, afternoon or evening and can also figure out what day it is.

fizbuzz

The Fizz Buzz is a technical question that can get asked during the hiring process. It seems pretty simple, but surprisingly many so called senior coders fail what one might consider a simple task.

zip

Learn a new module! Have a look at the zip module and see if you can combine your knowledge of filesystems with the zip library to come up with an interesting script.

compound interest

Compound interest problems can be solved using geometric series.

Convert the formula into Python code and create your own calculator.

Reading a file and filtering data

Create a txt file that looks like this:

name|grade|rating
brent|High Distinction|8
andrea|Pass|4
paul|Credit|5
sooty|No Grade|7

Use your knowledge from reading files to read this file and create a list that contains the names of everyone that has a rating higher than 5.

File System

I have a series of images that are saved in sequential order.

Imagine that I need to insert into the sequence - shot4b.png. I don’t want to call it shot4b.png, but what I would like to do is rename everything else in the sequence so that there is an empty spot for shot5.png where I can save the image to.

I.e.

  • shot5.png -> shot6.png
  • shot6.png -> shot7.png
shot1.png
shot2.png
shot3.png
shot4.png
shot6.png
shot7.png
...