Skip to content

Commit 7d819f3

Browse files
author
joy
committed
kyclark#1 joy.y
1 parent 8b49d04 commit 7d819f3

File tree

5 files changed

+246
-21
lines changed

5 files changed

+246
-21
lines changed

.gitignore

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,4 @@ tex2pdf*
1010
.log
1111
.coverage
1212
.idea
13-
.vscode
14-
02_crowsnest/crowsnest.py
15-
03_picnic/picnic.py
16-
04_jump_the_five/jump.py
17-
05_howler/howler.py
18-
06_wc/wc.py
19-
07_gashlycrumb/gashlycrumb.py
20-
08_apples_and_bananas/apples.py
21-
09_abuse/abuse.py
22-
10_telephone/telephone.py
23-
11_bottles_of_beer/bottles.py
24-
12_ransom/ransom.py
25-
13_twelve_days/twelve_days.py
26-
14_rhymer/rhymer.py
27-
15_kentucky_friar/friar.py
28-
16_scrambler/scrambler.py
29-
17_mad_libs/mad.py
30-
18_gematria/gematria.py
31-
19_wod/wod.py
32-
20_password/password.py
33-
21_tictactoe/tictactoe.py
13+
.vscode

01_hello/hello.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author: NowHappy <[email protected]>
4+
Purpose: Say Hello
5+
"""
6+
7+
import argparse
8+
9+
10+
# ---------------------------------------------------
11+
def get_args():
12+
"""Get the command-line arguments"""
13+
parser = argparse.ArgumentParser(description='Say Hello')
14+
parser.add_argument('-n', '--name', metavar='name',
15+
default='World', help='Name to greet')
16+
17+
return parser.parse_args()
18+
19+
20+
# ---------------------------------------------------
21+
def main():
22+
"""happy now"""
23+
args = get_args()
24+
print('Hello, ' + args.name + '!')
25+
26+
27+
# ---------------------------------------------------
28+
if __name__ == '__main__':
29+
main()

01_hello/hello2.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : kakao <kakao@localhost>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
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')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
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}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

01_hello/hello3.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : kakao <kakao@localhost>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
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')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
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}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

01_hello/hello4.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : NowHappy <[email protected]>
4+
Date : 2021-09-28
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Rock the Casbah',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
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')
48+
49+
return parser.parse_args()
50+
51+
52+
# --------------------------------------------------
53+
def main():
54+
"""Make a jazz noise here"""
55+
56+
args = get_args()
57+
str_arg = args.arg
58+
int_arg = args.int
59+
file_arg = args.file
60+
flag_arg = args.on
61+
pos_arg = args.positional
62+
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}"')
68+
69+
70+
# --------------------------------------------------
71+
if __name__ == '__main__':
72+
main()

0 commit comments

Comments
 (0)