Skip to content

Instantly share code, notes, and snippets.

@gkeramidas
Created June 28, 2018 23:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkeramidas/2f8720a0a259312beca79dffa7eaacfc to your computer and use it in GitHub Desktop.
Save gkeramidas/2f8720a0a259312beca79dffa7eaacfc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import argparse
import sys
def pluralize(count):
return "bugs" if count > 1 else "bug"
def bugs(count):
for k in range(1, count):
bug = pluralize(k)
more = k + 1
morebugs = pluralize(more)
yield (
f"{k} {bug} in my code on the wall, {k} {bug} in my code.\n" +
f"Take one down and pass it around, " +
f"{more} {morebugs} in my code on the wall."
)
def main():
parser = argparse.ArgumentParser(description="bugs on the wall")
parser.add_argument(
'-c', '--count',
metavar='NUM',
type=int,
default=100,
help=(
"How many bugs do you want in your code?"
),
)
args = parser.parse_args()
for line in bugs(args.count):
print(line)
print("")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Interrupted.")
sys.exit(1)
except Exception as ex:
print(f"Unhandled exception: {ex}")
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment