Skip to content

Commit b7669f5

Browse files
committed
Problem 04 solution
1 parent 88d29dd commit b7669f5

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

04_jump_the_five/jump.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Luke McGuire <[email protected]>
4+
Date : 2024-06-18
5+
Purpose: Jump the Five.
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description="Jump the Five.",
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
18+
)
19+
20+
parser.add_argument("message", metavar="str", help="Message to encode.")
21+
22+
return parser.parse_args()
23+
24+
25+
# --------------------------------------------------
26+
def main():
27+
"""Make a jazz noise here"""
28+
29+
args = get_args()
30+
# print(args.message.translate(str.maketrans("1234567890", "9876043215")))
31+
cipher = dict(zip("1234567890", "9876043215"))
32+
33+
# print("".join(cipher.get(c, c) for c in message))
34+
print(args.message.translate(str.maketrans(cipher)))
35+
36+
37+
# --------------------------------------------------
38+
if __name__ == "__main__":
39+
main()

04_jump_the_five/test.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from subprocess import getstatusoutput
66

7-
prg = './jump.py'
7+
prg = "./jump.py"
88

99

1010
# --------------------------------------------------
@@ -18,25 +18,25 @@ def test_exists():
1818
def test_usage():
1919
"""usage"""
2020

21-
for flag in ['-h', '--help']:
22-
rv, out = getstatusoutput(f'{prg} {flag}')
21+
for flag in ["-h", "--help"]:
22+
rv, out = getstatusoutput(f"python3 {prg} {flag}")
2323
assert rv == 0
24-
assert out.lower().startswith('usage')
24+
assert out.lower().startswith("usage")
2525

2626

2727
# --------------------------------------------------
2828
def test_01():
2929
"""test"""
3030

31-
rv, out = getstatusoutput(f'{prg} 123-456-7890')
31+
rv, out = getstatusoutput(f"python3 {prg} 123-456-7890")
3232
assert rv == 0
33-
assert out == '987-604-3215'
33+
assert out == "987-604-3215"
3434

3535

3636
# --------------------------------------------------
3737
def test_02():
3838
"""test"""
3939

40-
rv, out = getstatusoutput(f'{prg} "That number to call is 098-765-4321."')
40+
rv, out = getstatusoutput(f'python3 {prg} "That number to call is 098-765-4321."')
4141
assert rv == 0
42-
assert out.rstrip() == 'That number to call is 512-340-6789.'
42+
assert out.rstrip() == "That number to call is 512-340-6789."

0 commit comments

Comments
 (0)