An assignment requiring comparison between two numbers using recursion and without using structured objects is throwing me off because I cannot seem to simultaneously compare the numbers and keep track of how many numbers match.
def dm(n1, n2):
from decimal import getcontext, Decimal, ROUND_DOWN
if n1<0 or n2<0:
raise ValueError
elif n1//10 <1 or n2//10 <1:
n1v2, c, n2v2 = round(n1)%10, float(Decimal(n1)-Decimal(n1).quantize(Decimal(1.), rounding=ROUND_DOWN)), n2%10
if n1v2 == n2v2:
return int((c+.01) * 100)
elif c!= 0:
return int(c)*100
else:
return 0
elif type(n1) == float:
getcontext().rounding = ROUND_DOWN
n1v2, c, n2v2 = round(n1)%10, Decimal(n1)-Decimal(n1).quantize(Decimal(1.), rounding=ROUND_DOWN), n2%10
if n1v2 == n2v2:
dm(n1//10+(float(c)+.01), n2//10)
else:
dm(n1//10, n2//10)
else:
n1v2, n2v2 = n1%10, n2%10
if n1v2 == n2v2:
dm(float(n1//10+.01), n2//10)
else:
dm(float(n1//10), n2//10)
New contributor
finnsjunkmail is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1