Skip to content

Commit c98c3a7

Browse files
author
joy
committed
kyclark#3 joy.y
1 parent bc0b217 commit c98c3a7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

03_picnic/picnic.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : NowHappy <[email protected]>
4+
Date : 2021-09-30
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='Picnic game',
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
19+
parser.add_argument('item',
20+
nargs='+',
21+
metavar='str', # for help
22+
help='Item(s) to bring')
23+
24+
parser.add_argument('-s',
25+
'--sorted',
26+
help='Sort the items',
27+
action='store_true')
28+
29+
return parser.parse_args()
30+
31+
32+
# --------------------------------------------------
33+
def main():
34+
"""Make a jazz noise here"""
35+
36+
args = get_args()
37+
items = args.item
38+
num = len(items)
39+
40+
if args.sorted:
41+
items.sort()
42+
43+
if num < 2:
44+
print(f'You are bringing {items[0]}.')
45+
elif num < 3:
46+
print(f'You are bringing {items[0]} and {items[1]}.')
47+
else:
48+
items[-1] = 'and ' + items[-1]
49+
print('You are bringing ' + ', '.join(items) + '.')
50+
51+
52+
# --------------------------------------------------
53+
if __name__ == '__main__':
54+
main()

0 commit comments

Comments
 (0)