Sep-11-2020, 07:08 PM
First, put your code inside python tags so it is easily readable (and so indentation can be seen).
Second, how are you running it? Are you giving an argument to
You haven't told argparse that -n is required, so it will let you run without the argument. Also, the default is to read the argument as a string. So num_nums is a string and the print won't work when you ask it to format a string with %d.
You can modify the add_argument to resolve both. Something like
Second, how are you running it? Are you giving an argument to
-n
? When I do I get a str error instead of a NoneType error.You haven't told argparse that -n is required, so it will let you run without the argument. Also, the default is to read the argument as a string. So num_nums is a string and the print won't work when you ask it to format a string with %d.
You can modify the add_argument to resolve both. Something like
parser.add_argument("-n", type=int, required=True, help="Number to add")