2017-11-18 16:45:28 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Napisz funkcję sum_div35(n), która zwraca sumę wszystkich liczb podzielnych
|
|
|
|
przez 3 lub 5 mniejszych niż n.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def sum_div35(n):
|
2017-11-23 17:47:55 +01:00
|
|
|
new_range = range(n)
|
|
|
|
new_list = []
|
|
|
|
suma = 0
|
|
|
|
for n in new_range:
|
|
|
|
if n % 3 == 0 or n % 5 == 0:
|
|
|
|
new_list.append(n)
|
|
|
|
for x in new_list:
|
|
|
|
suma += x
|
|
|
|
return suma
|
2017-11-18 16:45:28 +01:00
|
|
|
|
|
|
|
def tests(f):
|
|
|
|
inputs = [[10], [100], [3845]]
|
|
|
|
outputs = [23, 2318, 3446403]
|
|
|
|
|
|
|
|
for input, output in zip(inputs, outputs):
|
|
|
|
if f(*input) != output:
|
|
|
|
return "ERROR: {}!={}".format(f(*input), output)
|
|
|
|
break
|
|
|
|
return "TESTS PASSED"
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print(tests(sum_div35))
|
|
|
|
|