I was asked a question about why the following code gives the following result:
def find(j):
if(j>1):
j=find(j//10)-(j%10)
print(j)
else:
j=0
return j
i=122
k=find(i)
RESULT:
-2
-4
Why that particular result? Here is what I have so far:
def find(j) – defying function find with j being an argument if j is greater than 1, the argument j within find function is divided by 10 122 % 10 = 2 print (j) – calls function find to display
From this point on, I am struggling. Why -2 and where is -4 coming from?
Aucun commentaire:
Enregistrer un commentaire