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