def last_dig(num1, num2, num3):
last_digit_mul = (num1%10) * (num2%10)
if last_digit_mul == (num3%10):
return True
else:
return False
last_dig(25, 21, 125)
This will output: True
The %
operator returns the remainder of the division of the number to it's left by the number to it's right. For example, 25%10
will return 5
which is the remainder of the division 25/10
, which is also the last digit.
I believe that was the troubling part as the rest is the same as your code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…