1
0
forked from tdwojak/Python2017
Python2017/labs02/task07.py
2017-11-27 21:23:07 +01:00

39 lines
774 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):
#sum([ord(litera) for litera in list(text)])
tablica=[]
def char_sum(text):
tablica.clear()
for litera in list(text):
tablica.append(ord(litera))
return(sum(tablica))
#tablica.clear()
#char_sum("this is a string")
#char_sum('a')
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))