python获取一组数个位数之和


pyschools Topic 2: Question 9  题目:给定一组整数,获取其个位数之和

Write a function getSumOfLastDigits() that takes in a list of positive numbers and returns the sum of all the last digits in the list.

def getSumOfLastDigits(numList): 
    return sum(x % 10 for x in numList)
getSumOfLastDigits([1, 23, 456])
Out[11]: 10


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM