Skip to content

Instantly share code, notes, and snippets.

@pszpetkowski
Last active October 20, 2016 21:28
Show Gist options
  • Select an option

  • Save pszpetkowski/24e067a19359a33d1028b176be4cfe76 to your computer and use it in GitHub Desktop.

Select an option

Save pszpetkowski/24e067a19359a33d1028b176be4cfe76 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def recursive_arithmetic_exception(depth=0, max_depth=20):
raise_string = (
'%stry:\n'
'%sraise ArithmeticError\n'
'%sexcept ArithmeticError:\n'
% (' ' * depth * 4, ' ' * (depth * 4 + 4), ' ' * depth * 4))
if depth < max_depth:
raise_string += recursive_arithmetic_exception(depth=depth+1, max_depth=max_depth)
if depth == 0:
raise_string += '%sraise ZeroDivisionError\n' % (' ' * (max_depth * 4 + 4))
return raise_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment