Created
June 28, 2018 23:17
-
-
Save gkeramidas/2f8720a0a259312beca79dffa7eaacfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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