Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

Function Where (Last Digit of first Number)*(last digit of second number)=(Last digit of Third Number) [PYTHON]

according to the title its clear i want to create a function which will return True, if(Last Digit of first Number)*(last digit of second number)=(Last digit of Third Number). else False.

I Would Like to clearly mention that i not know very well about this but still i tried several times. not all but here is my final try, if you know, please correct me if i am wrong somewhere like your disciple. Thank You.

def last_dig(num1,num2,num3):
  if num1[-1]*num2[-1]==num3[-1]:
    return True
  else:
    return False
last_dig(25, 21, 125)

Error was - TypeError: 'int' object is not subscriptable

question from:https://stackoverflow.com/questions/65869924/function-where-last-digit-of-first-numberlast-digit-of-second-number-last

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...