Skip to content

Commit c2529c1

Browse files
committed
working
1 parent 233e0cd commit c2529c1

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

apples_and_bananas/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_args():
1818

1919
parser.add_argument('-v',
2020
'--vowel',
21-
help='The vowel(s) allowed',
21+
help='The vowel to substitute',
2222
metavar='str',
2323
type=str,
2424
default='a',

apples_and_bananas/test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,38 @@ def test_bad_vowel():
3737

3838

3939
# --------------------------------------------------
40-
def test_01():
40+
def test_command_line():
4141
""" foo -> faa """
4242

4343
out = getoutput('{} foo'.format(prg))
4444
assert out.strip() == 'faa'
4545

4646

4747
# --------------------------------------------------
48-
def test_02():
48+
def test_command_line_with_vowel():
4949
""" foo -> fii """
5050

5151
out = getoutput('{} -v i foo'.format(prg))
5252
assert out.strip() == 'fii'
5353

54+
# --------------------------------------------------
55+
def test_command_line_with_vowel_preserve_case():
56+
""" foo -> fii """
57+
58+
out = getoutput('{} "APPLES AND BANANAS" --vowel i'.format(prg))
59+
assert out.strip() == 'IPPLIS IND BININIS'
60+
5461

5562
# --------------------------------------------------
56-
def test_03():
63+
def test_file():
5764
""" fox.txt """
5865

5966
out = getoutput('{} {}'.format(prg, fox))
6067
assert out.strip() == 'Tha qaack brawn fax jamps avar tha lazy dag.'
6168

6269

6370
# --------------------------------------------------
64-
def test_04():
71+
def test_file_with_vowel():
6572
""" fox.txt """
6673

6774
out = getoutput('{} --vowel o {}'.format(prg, fox))

gashlycrumb/solution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def main():
3030

3131
args = get_args()
3232
letter = args.letter
33-
lookup = {line[0]: line.rstrip() for line in args.file}
33+
lookup = {line[0].upper(): line.rstrip() for line in args.file}
3434

3535
if letter.upper() in lookup:
3636
print(lookup[letter.upper()])
3737
else:
38-
print('I do not know "{}".'.format(letter))
38+
print(f'I do not know "{letter}".')
3939

4040

4141
# --------------------------------------------------

howler/out.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

howler/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get_args():
1111
"""get command-line arguments"""
1212

1313
parser = argparse.ArgumentParser(
14-
description='Howler (upper-case input)',
14+
description='Howler (upper-cases input)',
1515
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
1616

1717
parser.add_argument('text', metavar='str', help='Input string or file')

jump_the_five/solution.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,26 @@ def main():
2222
"""Make a jazz noise here"""
2323

2424
args = get_args()
25-
text = args.text
2625
jumper = {'1': '9', '2': '8', '3': '7', '4': '6', '5': '0',
2726
'6': '4', '7': '3', '8': '2', '9': '1', '0': '5'}
2827

29-
for char in text:
30-
print(jumper.get(char, char), end='')
28+
# Method 1: for loop with print
29+
# for char in args.text:
30+
# print(jumper.get(char, char), end='')
31+
# print()
32+
33+
# Method 2: for loop to build new string
34+
# new_text = ''
35+
# for char in args.text:
36+
# new_text += jumper.get(char, char)
37+
# print(new_text)
38+
39+
# Method 3: list comprehension
40+
# print(''.join([jumper.get(char, char) for char in args.text]))
41+
42+
# Method 4: str.translate
43+
print(args.text.translate(str.maketrans(jumper)))
3144

32-
print()
3345

3446

3547
# --------------------------------------------------

0 commit comments

Comments
 (0)