import sys import math from lxml import etree def calculate_lcm(a, b): return abs(a * b) // math.gcd(a, b) def main(input_file): try: tree = etree.parse(input_file) except FileNotFoundError: print(f"Error: Input file '{input_file}' not found.") sys.exit(1) except etree.ParseError: print(f"Error: Failed to parse the XML file '{input_file}'.") sys.exit(1) root = tree.getroot() non_zero_values = [] for period_element in root.xpath("//period"): period_value = int(period_element.text) if period_value != 0: non_zero_values.append(period_value) if not non_zero_values: print("No non-zero values found in the XML file.") else: #print ("Periods: " + str (non_zero_values)); lcm = non_zero_values[0] for value in non_zero_values[1:]: lcm = calculate_lcm(lcm, value) feas = lcm * 2 print(feas) if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python script.py input_file.xmlv3") sys.exit(1) input_file = sys.argv[1] main(input_file)