Unable to see output in jupyter lite

You sort of answered yourself by finding where to post this. You have posted this under the title of ‘Unable to see output in jupyter lite’ because you are using JupyterLite that has a special kernel that doesn’t yet have all the abilities of a typical, fully-capable Python kernel (ipykernel). Note in the screenshot in the upper right corner of the kernel indicator where it says “(Pyodide)”.

See here and above there for how you have to change the code to work in JupyterLite using the special Pyodide kernel. Or keep that code & switch to using JupyterLab with a typical Python kernel (ipykernel) using MyBinder to serve you a temporary Jupyter session running on a remote machine. Google Colab also runs on a remote machine with a true Python kernel backing it. So to directly answer the last part of your post where you ponder “why not in jupyter”, that code does work in Jupyter if you use the corresponding tech.