In checking for amicable numbers I’ve made the following if-statement (dict is dictionary):
if n == dict[lib[n]]:
amic[n] = dict[n]
But if the n value is not in the dictionary it returns an error; as it should. But I’d like it to continue because an error means “it’s not equal” and it should continue to the next n.
Is this possible?
You probably want
dict.get()which returnsNone(or another default of your choosing). For examplen == lib.get(lib.get(n))