Numeroarpoja


      






import random import pyodide currIndex = 0 buff = "" lstRandom = [] count = 0 def new_round(xx): global currIndex global buff pyscript.write('btn_next', "Arvo numero 1!") currIndex = 0 buff = "" pyscript.write('numbers_area', "") js.document.getElementById('btn_new').style.visibility = 'hidden'; js.document.getElementById('btn_next').style.visibility = 'visible'; js.document.getElementById('btn_amount').style.visibility = 'visible'; def next_number(*ags, **kws): global currIndex global lstRandom global buff global count if currIndex == 0: js.document.getElementById('btn_amount').style.visibility = 'hidden'; count = js.document.getElementById('btn_amount').value; lstRandom = [str(i) for i in range(1, int(count) + 1)] random.shuffle(lstRandom) js.document.getElementById('btn_new').style.visibility = 'visible'; currIndex += 1 buff = "numero{0:3}: {1:2}".format(currIndex, lstRandom[currIndex - 1]) + "\n" + buff pyscript.write('numbers_area', buff) if currIndex == len(lstRandom): js.document.getElementById('btn_next').style.visibility = 'hidden'; pyscript.write('btn_new', "Arvo uudestaan!") else: pyscript.write('btn_new', "Lopeta kierros") pyscript.write('btn_next', "Arvo numero " + str(currIndex + 1) + " / " + str(count)) btnElem = js.document.getElementById('btn_next') btnElem.addEventListener('click', pyodide.ffi.create_proxy(next_number)) btnElem = js.document.getElementById('btn_new') btnElem.addEventListener('click', pyodide.ffi.create_proxy(new_round)) js.document.getElementById('btn_new').style.visibility = 'hidden';