Store standard output on a variable in Python

This is a great, hacky trick to get the standard output ( and others like standard error and standard input) in Python You can “redirect” the standard error changing the sys.stdout module with your own StringIO object. So, you can do something like Easy and very useful!   EDITED: Updated to make it work for Python 3.4

$7.11 in four prices and the Decimal type

There’s an fun and not very difficult programming exercise, presented on Programming Praxis . The problem is easy to describe: “A mathematician purchased four items in a grocery store. He noticed that when he added the prices of the four items, the sum came to $7.11, and when he multiplied the prices of the four items, the product came to $7.11.” Ok, the problem is easy to get on a brute force approach. Just try all the combinations, see their sum and multiplication, and find the one that gets it. Well, easy,… Read More