Skip to content
Advertisement

Getting KeyError in the following code to find “minimum number square to the number”

I am getting the error in the following code for the above stated problem using memoization please help me find the error and correct the code.

JavaScript

Advertisement

Answer

It would help if you provided the full error output, which should include the line number and surrounding code. However, I suspect the issue lies in the following line:

JavaScript

You’re checking whether the value of a dictionary key exists as a dictionary key. I assume you actually meant this (which will check whether a value is an existing dictionary key):

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement