0
0
Fork 0
Python2018/labs02/task08.py

32 lines
652 B
Python
Raw Permalink Normal View History

2018-05-12 11:37:19 +02: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):
2018-06-02 11:40:48 +02:00
suma = 0
for liczba in range(n):
if (liczba % 3 == 0) or (liczba % 5 == 0):
suma = suma + liczba
return suma
2018-05-12 11:37:19 +02: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))
2018-06-02 11:40:48 +02:00