Binimate
#
# binimate.py
#
# Full example with unit tests
# binimate(s): kill every other character and return the result
def binimate(s):
= ""
result for i in range(len(s)):
if i%2==0:
+= s[i]
result return result
# unit test function: run the function binimate() and verify the
# output is what you expect
def test_binimate(s, expected):
= binimate(s)
result print("s:", s, "expected:", expected, "result:", result)
if result == expected:
print("Woohoo!")
else:
print("Boohoo!")
# multiple unit tests
"Dr. Kessner", "D.Ksnr");
test_binimate("Briley", "Bie");
test_binimate("Jasmine", "Jsie");
test_binimate("Sophia", "Spi");
test_binimate(
Output:
s: Dr. Kessner expected: D.Ksnr result: D.Ksnr
Woohoo!
s: Briley expected: Bie result: Bie
Woohoo!
s: Jasmine expected: Jsie result: Jsie
Woohoo!
s: Sophia expected: Spi result: Spi
Woohoo!