1
0
Fork 0
Python2017/labs02/task07.py

30 lines
746 B
Python
Raw Normal View History

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-25 15:19:18 +01:00
sumaAsci = 0
2017-11-26 14:03:31 +01:00
text_tmp = str(text)
text_tmp=text_tmp.replace('[','')
text_tmp = text_tmp.replace(']', '')
text_tmp = text_tmp.replace("'", '')
for i in text_tmp:
sumaAsci += ord(i)
2017-11-25 15:19:18 +01:00
return sumaAsci
2017-11-18 16:45:28 +01: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))