forked from tdwojak/Python2018
29 lines
656 B
Python
29 lines
656 B
Python
|
#!/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):
|
||
|
i, suma = 1, 0
|
||
|
for i in range(1, n):
|
||
|
if not (i % 3 and i % 5):
|
||
|
suma += i
|
||
|
i += 1
|
||
|
return suma
|
||
|
sum_div35(10)
|
||
|
|
||
|
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))
|