Last active
June 8, 2022 16:53
-
-
Save SahbiOuali13/bc2909710a15a62294fc9460b6cfc965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Create a function that accepts a string. The function should return a string, with each character doubled. | |
E.g. MMaarrttiinn | |
""" | |
def double_characters(word): | |
if not word: | |
raise ValueError('You gave an empty list.') | |
double = "" | |
for character in word: | |
double += character * 2 | |
return double | |
if __name__ == "__main__": | |
word = "Martin" | |
print(double_characters(word)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from double import double_characters | |
class TestDouble(unittest.TestCase): | |
def test_double_characters_double_characters(self): | |
self.assertEqual(double_characters('Martin'), 'MMaarrttiinn') | |
self.assertEqual(double_characters('Tree'), 'TTrreeee') | |
def test_double_charcaters_fails_on_empty_string(self): | |
self.assertRaises(ValueError, double_characters, '') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment