import json with open("flowchart.json", "r") as f: data = json.load(f) def…
- User
import json
with open("flowchart.json", "r") as f: data = json.load(f)
def navigate_flowchart(node): if isinstance(node, str): if node.startswith("start"): start_index = int(node.split(" ")[1]) node = data[f"start {start_index}"] navigate_flowchart(node) else: print(node) return
question = node.get("question") path = node.get("path") if question: print(question) options = { idx: key for idx, key in enumerate(node.keys()) if key not in ["question", "path"] } for option_num, option_key in options.items(): option_value = node[option_key] if isinstance(option_value, dict) and "path" in option_value: print(f"{option_num}. {option_key}") else: print(f"{option_num}. {option_key}") while True: user_input = input("Enter the option number: ") try: user_input = int(user_input) if user_input in options: next_node_key = list(options.values())[user_input - 1] next_node = node[next_node_key] break else: print("Invalid option number. Please try again.") except ValueError: print("Invalid input. Please enter a number.") elif path: path_str = node["path"] print(path_str) path_options = node.get(path_str, {}) for option_num, option_key in enumerate(path_options.keys(), start=1): if option_key != "question": print(f"{option_num}. {option_key}") while True: user_path_input = input("Enter the option number: ") try: user_path_input = int(user_path_input) if user_path_input <= len(path_options) and user_path_input > 0: next_node_key = list(path_options.keys())[user_path_input - 1] next_node = path_options[next_node_key] break else: print("Invalid option number. Please try again.") except ValueError: print("Invalid input. Please enter a number.") else: next_node = {} navigate_flowchart(next_node)Start the navigation from the "start" node
navigate_flowchart(data["start"])
write a html code to port this to a website instead of python cli
- Assistant
- User
first convert the python cli to javascript python cli
- Assistant