forked from tdwojak/Python2017
a4c07e0d39
Signed-off-by: s45167 <krzysztof.spalinski@op.pl>
35 lines
685 B
Python
35 lines
685 B
Python
#!/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):
|
|
xN=range(1,n+1)
|
|
xSum = 0
|
|
if n<1:
|
|
xSum=0
|
|
else:
|
|
for i in xN:
|
|
xSum += i
|
|
|
|
return xSum
|
|
|
|
#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__":
|
|
print(tests(sum_from_one_to_n))
|