File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """
3+ Author : NowHappy <rlfmalehd@gmail.com>
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 ()
You can’t perform that action at this time.
0 commit comments