Added 'import sys' to code so that it works.