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"
if b < c:
print "like an"
print "flies like"
if ( a < b ) & ( c > b ):
print "a banana"
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.
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)
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?