Skip to content

Commit 8ad47ad

Browse files
authored
Merge pull request #4 from JBSP-code/chapter_04
Chapter 04
2 parents b2e641b + 36fd2d1 commit 8ad47ad

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ tex2pdf*
1111
.coverage
1212
.idea
1313
.vscode
14-
04_jump_the_five/jump.py
1514
05_howler/howler.py
1615
06_wc/wc.py
1716
07_gashlycrumb/gashlycrumb.py

04_jump_the_five/jump.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Jeffrey Paz-Schmid
4+
Date : 2023-01-22
5+
Purpose: Encode Phone-Numbers
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("text", metavar="str", help="Input text")
21+
22+
return parser.parse_args()
23+
24+
25+
# --------------------------------------------------
26+
def main():
27+
"""Make a jazz noise here"""
28+
29+
args = get_args()
30+
31+
jumper = {
32+
"1": "9",
33+
"2": "8",
34+
"3": "7",
35+
"4": "6",
36+
"5": "0",
37+
"6": "4",
38+
"7": "3",
39+
"8": "2",
40+
"9": "1",
41+
"0": "5",
42+
}
43+
44+
print("".join([jumper.get(char, char) for char in args.text]))
45+
46+
47+
# --------------------------------------------------
48+
if __name__ == "__main__":
49+
main()

04_jump_the_five/test.py

Lines changed: 7 additions & 7 deletions
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,19 +18,19 @@ 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"{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"{prg} 123-456-7890")
3232
assert rv == 0
33-
assert out == '987-604-3215'
33+
assert out == "987-604-3215"
3434

3535

3636
# --------------------------------------------------
@@ -39,4 +39,4 @@ def test_02():
3939

4040
rv, out = getstatusoutput(f'{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)