File tree 1 file changed +15
-5
lines changed
1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ def get_args():
17
17
formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
18
18
)
19
19
20
- parser .add_argument ("positional " , metavar = "str" , help = "Item(s) to bring" )
20
+ parser .add_argument ("items " , metavar = "str" , help = "Item(s) to bring" , nargs = "+ " )
21
21
22
22
parser .add_argument ("-s" , "--sorted" , help = "Sort the items" , action = "store_true" )
23
23
@@ -29,11 +29,21 @@ def main():
29
29
"""Make a jazz noise here"""
30
30
31
31
args = get_args ()
32
- sort_flag = args .on
33
- items = args .str
32
+ sort_flag = args .sorted
33
+ items = args .items
34
34
35
- print (f'flag_arg = "{ sort_flag } "' )
36
- print (f'positional = "{ items } "' )
35
+ if sort_flag == True :
36
+ items .sort ()
37
+
38
+ if len (items ) >= 3 :
39
+ items .insert (- 1 , "and " )
40
+ items_to_bring = ", " .join (items [:- 1 ]) + items [- 1 ]
41
+ elif len (items ) == 2 :
42
+ items_to_bring = " and " .join (items )
43
+ else :
44
+ items_to_bring = items [0 ]
45
+
46
+ print ("You are bringing " + items_to_bring + "." )
37
47
38
48
39
49
# --------------------------------------------------
You can’t perform that action at this time.
0 commit comments