나는 이렇게 학습한다/Algorithm & SQL

Sum of all the multiples of 3 or 5

daco2020 2022. 7. 20. 23:30
반응형

Your task is to write function findSum.

Upto and including n, this function will return the sum of all multiples of 3 and 5.

For example:

findSum(5) should return 8 (3 + 5)

findSum(10) should return 33 (3 + 5 + 6 + 9 + 10)

 

 

Solution:

def find(n):
    return sum([i for i in range(1, n+1) if i%3 == 0 or i%5 == 0])

1. Find a number less than 'n'.
2. Find a number that is divisible by 3 or divisible by 5.
3. Add up all the numbers found.

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Replace With Alphabet Position  (0) 2022.07.22
Anagram Detection  (0) 2022.07.21
SQL Basics: Simple JOIN with COUNT  (0) 2022.07.19
SQL Basics: Simple HAVING  (0) 2022.07.19
Hello SQL World!  (0) 2022.07.17