I'm trying to resolve the errors in this code. We are trying to use argparse, and I get to num_nums = len(args.n) and I get errors. The error gets generated when reading the next line and reads as:
ERROR CODE
I am looking for assistance with the code to get it to a working state. Full code is:
ERROR CODE
Error:print("Adding %d numbers." % num_nums)
TypeError: %d format: a number is required, not NoneType
I can't figure out what is failing with the %d argument that is being passed.I am looking for assistance with the code to get it to a working state. Full code is:
import argparse parser = argparse.ArgumentParser() parser.add_argument("-n", help="Number to add") parser.add_argument("--indent", help="Indent output") args = parser.parse_args() num_nums = (args.n) print("Adding %d numbers." % num_nums) sum = 0 for n in range(0, num_nums): sum = sum + args.n[n] if (args.i): print("\tSum = %d" % sum) else: print("Sum = %d" % sum)