2018-05-12 11:37:19 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Napisz funkcję sum_from_one_to_n zwracającą sume liczb od 1 do n.
|
|
|
|
Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def sum_from_one_to_n(n):
|
2018-05-13 10:55:34 +02:00
|
|
|
if n > 1:
|
|
|
|
wynik = 0
|
|
|
|
for i in range(n+1):
|
|
|
|
wynik = i + wynik
|
|
|
|
return wynik
|
|
|
|
else: return 0
|
2018-05-12 11:37:19 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def tests(f):
|
|
|
|
inputs = [[999], [-100]]
|
|
|
|
outputs = [499500, 0]
|
|
|
|
|
|
|
|
for input, output in zip(inputs, outputs):
|
|
|
|
if f(*input) != output:
|
|
|
|
return "ERROR: {}!={}".format(f(*input), output)
|
|
|
|
break
|
|
|
|
return "TESTS PASSED"
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-05-13 10:55:34 +02:00
|
|
|
print(tests(sum_from_one_to_n))
|