From ba8e16602849aeb9eaf647ab995591f098697b30 Mon Sep 17 00:00:00 2001 From: Austinito Date: Sun, 31 Jul 2022 09:07:30 -0700 Subject: [PATCH 1/4] Finish the first two exercises --- .gitignore | 20 ----------------- 01_hello/hello.py | 32 ++++++++++++++++++++++++++++ 02_crowsnest/crowsnest.py | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 20 deletions(-) create mode 100755 01_hello/hello.py create mode 100755 02_crowsnest/crowsnest.py diff --git a/.gitignore b/.gitignore index 68ca39690..35db47f33 100644 --- a/.gitignore +++ b/.gitignore @@ -11,23 +11,3 @@ tex2pdf* .coverage .idea .vscode -02_crowsnest/crowsnest.py -03_picnic/picnic.py -04_jump_the_five/jump.py -05_howler/howler.py -06_wc/wc.py -07_gashlycrumb/gashlycrumb.py -08_apples_and_bananas/apples.py -09_abuse/abuse.py -10_telephone/telephone.py -11_bottles_of_beer/bottles.py -12_ransom/ransom.py -13_twelve_days/twelve_days.py -14_rhymer/rhymer.py -15_kentucky_friar/friar.py -16_scrambler/scrambler.py -17_mad_libs/mad.py -18_gematria/gematria.py -19_wod/wod.py -20_password/password.py -21_tictactoe/tictactoe.py diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100755 index 000000000..4ef4a48c9 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +""" +Purpose: Say hello +""" +# Purpose: Say hello + +import argparse + + +def get_args(): + """Get the command-line arguments""" + + parser = argparse.ArgumentParser(description='Say hello') + parser.add_argument( + '-n', + '--name', + metavar='name', + default='World', + help='Name to greet' + ) + return parser.parse_args() + + +def main(): + """main""" + + args = get_args() + print(f'Hello, {args.name}!') + + +if __name__ == '__main__': + main() diff --git a/02_crowsnest/crowsnest.py b/02_crowsnest/crowsnest.py new file mode 100755 index 000000000..d6778b5b7 --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +""" +Author : Austinito +Date : 2022-07-31 +Purpose: Shout whatever you see +""" + +import argparse + + +VOWELS = ['a', 'e', 'i', 'o', 'u'] + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description="Crow's Nest -- choose the correct article", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('word', metavar='str', help='A word') + + return parser.parse_args() + + +# -------------------------------------------------- +def get_correct_article(word: str): + """Get correct article for given str""" + return 'an' if word[0].lower() in VOWELS else 'a' + + +# -------------------------------------------------- +def main(): + """Where it begins...""" + + args = get_args() + word = args.word + article = get_correct_article(word) + print(f'Ahoy, Captain, {article} {word} off the larboard bow!') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() From 3d4d467a7fbe2ce4703150804f1bb0acdba79aa4 Mon Sep 17 00:00:00 2001 From: Austinito Date: Sat, 6 Aug 2022 08:14:13 -0700 Subject: [PATCH 2/4] finish picnic project --- 03_picnic/picnic.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 03_picnic/picnic.py diff --git a/03_picnic/picnic.py b/03_picnic/picnic.py new file mode 100755 index 000000000..25f218207 --- /dev/null +++ b/03_picnic/picnic.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +""" +Author : Austinito +Date : 2022-08-06 +Purpose: Correcly format the items we're taking on our picnic. +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Picnic game', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('items', + metavar='str', + nargs='+', + help='Item(s) to bring') + + parser.add_argument('-s', + '--sorted', + help='Sort the items', + action='store_true', + ) + + return parser.parse_args() + + +# -------------------------------------------------- +def mk_string_with_oxford_comma(items: list[str]): + """Combines a list of strings with oxford comma rules""" + if len(items) > 1: + last = items.pop() + if len(items) > 1: + return ', '.join(items) + ', and ' + last + return ''.join(items) + ' and ' + last + return ''.join(items) + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + items = args.items + + if args.sorted: + items.sort() + + pretty_items = mk_string_with_oxford_comma(items) + + print(f'You are bringing {pretty_items}.') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() From e0d39fb3e84254d317e48de02cfbe16eff9f0699 Mon Sep 17 00:00:00 2001 From: Austinito Date: Sat, 13 Aug 2022 09:28:40 -0700 Subject: [PATCH 3/4] Finished jump_the_five --- 04_jump_the_five/jump.py | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 04_jump_the_five/jump.py diff --git a/04_jump_the_five/jump.py b/04_jump_the_five/jump.py new file mode 100755 index 000000000..ed9732891 --- /dev/null +++ b/04_jump_the_five/jump.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +""" +Author : Austinito +Date : 2022-08-13 +Purpose: Obfuscate numbers +""" + +import argparse + + +JUMPER = { + '1': '9', + '2': '8', + '3': '7', + '4': '6', + '5': '0', + '6': '4', + '7': '3', + '8': '2', + '9': '1', + '0': '5' + } + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Jump the Five', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('positional', metavar='str', help='Input text') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + pos_arg: str = args.positional + + res = '' + for char in pos_arg: + res += JUMPER[char] if char.isdigit() else char + + print(res) + + +# -------------------------------------------------- +if __name__ == '__main__': + main() From 177749b72717ae0f6df2f142168650e9748aae2c Mon Sep 17 00:00:00 2001 From: Austinito Date: Mon, 15 Aug 2022 21:31:06 -0700 Subject: [PATCH 4/4] Finish File input & output project --- 05_howler/howler.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 05_howler/howler.py diff --git a/05_howler/howler.py b/05_howler/howler.py new file mode 100755 index 000000000..72f39e724 --- /dev/null +++ b/05_howler/howler.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +""" +Author : austinherrera +Date : 2022-08-13 +Purpose: Transform text into UPPERCASE message. +""" + +import argparse +import os + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Howler (upper-cases input)', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('input', + metavar='str', + help='Input string or file') + + parser.add_argument('-o', + '--outfile', + help='Output filename', + metavar='str', + type=str, + default='') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """And it begins...""" + + args = get_args() + command_input = args.input + output_file = args.outfile + + input_string_or_file = "" + if os.path.isfile(command_input): + input_string_or_file = open(command_input, 'r').read().rstrip() + else: + input_string_or_file += command_input + + if output_file: + out_fh = open(output_file, 'wt') + out_fh.write(input_string_or_file.upper()) + else: + print(input_string_or_file.upper()) + + +# -------------------------------------------------- +if __name__ == '__main__': + main()