2018-05-12 11:37:19 +02: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):
|
2018-05-13 10:08:22 +02:00
|
|
|
|
2018-05-13 10:07:40 +02:00
|
|
|
sumujemy = 0
|
2018-05-13 10:08:22 +02:00
|
|
|
|
2018-05-13 10:07:40 +02:00
|
|
|
for znaki in text:
|
2018-05-13 10:08:22 +02:00
|
|
|
|
2018-05-13 10:07:40 +02:00
|
|
|
sumujemy = sumujemy + ord(znaki)
|
2018-05-13 10:08:22 +02:00
|
|
|
|
|
|
|
|
2018-05-13 10:07:40 +02:00
|
|
|
return sumujemy
|
|
|
|
|
2018-05-12 11:37:19 +02:00
|
|
|
|
|
|
|
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))
|