Code example

Although the example is very simple, the basic approach to finding solutions for business-critical challenges is all here – understanding the issue, the code, and how to manipulate code to achieve the desired outcome.

if a < b:
print "Time flies"
else:
print "Fruit"
if b < c:
print "like an"
else:
print "flies like"
if ( a < b ) & ( c > b ):
print "arrow"
else:
print "a banana"

What does this program output (print out) for the input values (a = 1, b = 2, c = 3)?

Click here for the answer

Answer: “Time flies like an arrow” – if you didn’t get this, try stepping through the code block by block to identify the output from each block.

What input values of a, b and c are needed to output “Fruit flies like a banana”?

Click here for the answer

Answer: Any value of a which is greater or equivalent to b, plus any value of b which is greater or equivalent to c – e.g. (a = 3, b = 2, c = 1)

What other possible outputs are there for this program?

Click here for the answer

Answer: Only two other strings can be output: “Time flies flies like a banana” and “Fruit like an a banana”. It’s not possible to output “Time flies like an a banana”, “Time flies flies like arrow”, “Fruit like an arrow” or “Fruit flies like arrow” – try it for yourself!

If you found this example enjoyable and would relish the intellectual challenge of producing code that underpins our innovative business solutions, why not apply for the IT graduate programme?