Apr-16-2023, 04:08 PM
I have updated the code as follows:
<html> <head> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <input type="text" id="input_str"/> <input type="number" id="n"/> <button id="submit-button" type="button" py-click="my_function()">OK</button> <div id="test-output"></div> <p>Output:</p> <p id='output'></p> <py-config> packages = ["numpy"] </py-config> <py-script> import numpy as np from pyscript import Element def my_function(): input_str = Element('input_str').value n = int(Element('n').value) input_list = input_str.split(",") w = [] for num in input_list: w.append(int(num)) rows = len(w) // n A = np.zeros((rows, n)) for i in range(len(w)): if (w[i] % n == 0): A[w[i]//n - 1, n-1] = int(i+1) else: A[w[i]//n, w[i]%n-1] = int(i+1) result_place = Element('output') result_place.write(str(A)) </py-script> </body> </html>However, now it gives the following error message:
Error:NameError: name 'input_str' is not defined
Any ideas to fix it?