2017-11-18 16:45:28 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
|
|
|
|
sumę kodów ASCII znaków.
|
|
|
|
"""
|
|
|
|
def char_sum(text):
|
2017-11-30 21:57:16 +01:00
|
|
|
return sum(ord(i) for i in text)
|
2017-11-18 16:45:28 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
def tests(f):
|
|
|
|
inputs = [["this is a string"], ["this is another string"]]
|
|
|
|
outputs = [1516, 2172]
|
|
|
|
|
|
|
|
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(char_sum))
|