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

Skip to content

Commit 0c95a1a

Browse files
committed
First Chapter Completed
1 parent cb474dd commit 0c95a1a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

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: Sudhanshu Tiwari <[email protected]>
4+
Purpose: Say Hello
5+
"""
6+
7+
import argparse
8+
9+
10+
def get_args():
11+
"""Get the command-line arguments"""
12+
parser = argparse.ArgumentParser(description='Say hello')
13+
parser.add_argument('-n',
14+
'--name',
15+
metavar="name",
16+
default='World',
17+
help='Name to greet')
18+
return parser.parse_args()
19+
20+
21+
def main():
22+
"""Make a jazz noise here"""
23+
24+
args = get_args()
25+
print('Hello, ' + args.name + '!')
26+
27+
28+
if __name__ == '__main__':
29+
main()

01_hello/hello2.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : sudhanshu <sudhanshu@localhost>
4+
Date : 2020-11-09
5+
Purpose: Say Hello
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
15+
parser = argparse.ArgumentParser(
16+
description='Say Hello',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('-n',
20+
'--name',
21+
help='Name to greet',
22+
metavar='name',
23+
type=str,
24+
default='World')
25+
26+
27+
28+
return parser.parse_args()
29+
30+
# --------------------------------------------------
31+
def main():
32+
"""Make a jazz noise here"""
33+
34+
args = get_args()
35+
name = args.name
36+
37+
print('Hello, ' + name + '!')
38+
39+
40+
41+
# --------------------------------------------------
42+
if __name__ == '__main__':
43+
main()

0 commit comments

Comments
 (0)