Input and Int are not registering as functions

I am using an Anaconda-launched Jupyter Notebook and the Python 3 ipy kernel. I have seen others with similar problems, on the same project too! However, I am unsure if the solutions and issues fit exactly what I am experiencing.

I ran the script in the screenshot for all of 30 minutes before suddenly my int(input() was no longer highlighted and the guess variable now has a Name Error. See the screenshot below.

to be able to compare guess with number it needs to be defined before the while loop.

And this is not pertinent to this forum per se. I suspect if you ran this code in an IPython session, you’d get the same issue. Or as Python in a interpreter/console. That makes it a Python / IPython coding issue.

It does though sound like you had one issue that you could benefit from a tip for better use of Jupyter, pehaps. It sounds like things were working and then 30 minutes later your code didn’t work, right? If you restart the kernel often and run all the code (or at least all the code above the place you are currently working, in the case of notebooks with more cells than your example here) you probably would have noticed the issue earlier. (There’s a menu choice to do just that under the ‘Kernel’ menu along the top.) That is a good habit to get in as it helps you avoid the hidden state issue better. Or at least encounter the issue sooner while you remember what you were changing recently. The hidden state here was probably at some point you defined guess as a value of some sort and that was in the namespace having been run. Then you changed or removed the code that was defining that, but at that point your code still worked because guess was defined in the namespace, i.e, ‘the hidden state’. Still later though you cleared the namespace either entirely (or at least of guess) somehow. However, you don’t seem to recall that now. And not your code doesn’t work because guess isn’t defined and you don’t have step defining it before you try to use it. If you had been in a habit of restarting the kernel and running all the cells (or all above a point you are at in drafting the notebook) you’d have noted things earlier. You’ll have a better coding experience and produce more robust Jupyter .ipynb files if you do that more often going forward.

Another tip for Jupyter and IPython that would help you in troubleshooting/understanding, is you can check defined variables and the values with the magic %whos, see here. There’s more general things you can look into for Python that work in Jupyter, too, see here.

And I see you have a link to open that over in JupyterLab above your notebook in the screenshot. There you have a Visual debugger that you can use to step through running and displaying the defined variables as it runs, see JupyterLab Visual Debugger Usage here.

1 Like