forked from tdwojak/Python2017
37 lines
941 B
Python
37 lines
941 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
#text = [["aaa"], ["bbb"], ["this is another string"]]
|
||
|
#text = "aaa"
|
||
|
text = [["this is a string"], ["this is another string"]]
|
||
|
|
||
|
def char_sum(text):
|
||
|
if isinstance(text, str):
|
||
|
def form_ascii(text):
|
||
|
print(sum(map(ord, text)))
|
||
|
return form_ascii(text)
|
||
|
elif isinstance(text, list):
|
||
|
def ascii_list(text):
|
||
|
loc = [sub_list[0] for sub_list in text]
|
||
|
for i in loc:
|
||
|
print(sum(map(ord, i)))
|
||
|
return ascii_list(text)
|
||
|
else:
|
||
|
print("try harder")
|
||
|
|
||
|
|
||
|
char_sum(text)
|
||
|
|
||
|
|
||
|
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))
|