forked from tdwojak/Python2017
30 lines
784 B
Python
30 lines
784 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.
|
||
|
"""
|
||
|
#pythonowy zakres dla funkcji range: range(3) == [0, 1, 2], czyli <n to range(n)
|
||
|
#example sum in range: for x in range(100, 2001, 3); 100 - 2001 range, divided by 3
|
||
|
|
||
|
|
||
|
#n = 100
|
||
|
def sum_div35(n):
|
||
|
return sum(range(3, n, 3)) + sum(range(5, n, 5)) - sum(range(15, n, 15))
|
||
|
print(sum_div35(n))
|
||
|
|
||
|
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))
|
||
|
|