a = 5
html_code = (
    """
<html>
  <head>
    <script type="text/javascript">
    window.alert(%s);
    </script>
  </head>
</html>"""
     % a)
from IPython.display import HTML
Pass a variable in IPython / Jupyter to a block of html (%%html)