import sys # Read a file specified by the first command line argument. # Print the number of characters in the file and then the file itself. if len(sys.argv) < 2: print("Usage: sum_number.py ") sys.exit(1) # Exit with an error code filename = sys.argv[1] try: with open(filename, mode="r") as f: """ sum = 0 for line in f: sum += int(line) """ sum = 0 lines = f.readlines() for line in lines: sum += int(line) print(f"total sum is {sum}.") print(f"There are {len(lines)} numbers.") except FileNotFoundError: print(f"The file {filename} cannot be found.") sys.exit(1) except Exception as e: print(f"An error occurred: {e}")