1
0
forked from tdwojak/Python2018
Python2018/labs02/task07.py
Sylwia Miśkiewicz 1bf2836b87 in progres
2018-05-29 20:58:35 +02:00

25 lines
586 B
Python

#!/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):
z = list(text)
lista = [ord(x) for x in z]
return sum(lista)
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))