본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 14

반응형

Q>

1 ~ 100까지의 자연수 중 3과 5의 공배수를 출력하면서 그에 대한 총합을 구하시오.


A>

sum = 0

for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
sum += i
print(i)

result = ("공배수의 총 합 : {0}".format(sum))

print(result)


O>

15

30

45

60

75

90

공배수의 총 합 : 315


Process finished with exit code 0

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 16  (0) 2019.03.27
Python Learn the basics Quiz 15  (0) 2019.03.27
Python Learn the basics Quiz 13  (0) 2019.03.18
Python Learn the basics Quiz 12  (0) 2019.03.18
Python Learn the basics Quiz 11  (0) 2019.03.18