forked from tdwojak/Python2018
33 lines
725 B
Python
33 lines
725 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.
|
|
"""
|
|
|
|
"""
|
|
ord() - kod ASCII dla jednego znaku
|
|
print(ord('a'))
|
|
"""
|
|
|
|
def char_sum(text):
|
|
suma_ascii = 0 # zerujemy (needto?)
|
|
for znak in text:
|
|
suma_ascii += ord(znak) # suma_ascii = ord(x) + suma_ascii
|
|
return suma_ascii
|
|
|
|
|
|
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))
|