Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abdbe66

Browse files
committed
ch04: valid solution
1 parent 489e4b7 commit abdbe66

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

04_jump_the_five/jump.py

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22
"""
3-
Author : Anonymous <Anonymous@localhost>
3+
Author : Jeffrey Paz-Schmid
44
Date : 2023-01-22
5-
Purpose: Rock the Casbah
5+
Purpose: Encode Phone-Numbers
66
"""
77

88
import argparse
@@ -13,38 +13,11 @@ def get_args():
1313
"""Get command-line arguments"""
1414

1515
parser = argparse.ArgumentParser(
16-
description='Rock the Casbah',
17-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
16+
description="Jump the Five",
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
18+
)
1819

19-
parser.add_argument('positional',
20-
metavar='str',
21-
help='A positional argument')
22-
23-
parser.add_argument('-a',
24-
'--arg',
25-
help='A named string argument',
26-
metavar='str',
27-
type=str,
28-
default='')
29-
30-
parser.add_argument('-i',
31-
'--int',
32-
help='A named integer argument',
33-
metavar='int',
34-
type=int,
35-
default=0)
36-
37-
parser.add_argument('-f',
38-
'--file',
39-
help='A readable file',
40-
metavar='FILE',
41-
type=argparse.FileType('rt'),
42-
default=None)
43-
44-
parser.add_argument('-o',
45-
'--on',
46-
help='A boolean flag',
47-
action='store_true')
20+
parser.add_argument("positional", metavar="str", help="Input text")
4821

4922
return parser.parse_args()
5023

@@ -54,19 +27,28 @@ def main():
5427
"""Make a jazz noise here"""
5528

5629
args = get_args()
57-
str_arg = args.arg
58-
int_arg = args.int
59-
file_arg = args.file
60-
flag_arg = args.on
6130
pos_arg = args.positional
6231

63-
print(f'str_arg = "{str_arg}"')
64-
print(f'int_arg = "{int_arg}"')
65-
print('file_arg = "{}"'.format(file_arg.name if file_arg else ''))
66-
print(f'flag_arg = "{flag_arg}"')
67-
print(f'positional = "{pos_arg}"')
32+
jumper = {
33+
"1": "9",
34+
"2": "8",
35+
"3": "7",
36+
"4": "6",
37+
"5": "0",
38+
"6": "4",
39+
"7": "3",
40+
"8": "2",
41+
"9": "1",
42+
"0": "5",
43+
}
44+
45+
for char in pos_arg:
46+
if char in jumper:
47+
print(jumper[char], end="")
48+
else:
49+
print(char, end="")
6850

6951

7052
# --------------------------------------------------
71-
if __name__ == '__main__':
53+
if __name__ == "__main__":
7254
main()

0 commit comments

Comments
 (0)