Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Last active November 12, 2020 05:21
Show Gist options
  • Save ZechCodes/62258aeeb94809a8c5f829095af09aec to your computer and use it in GitHub Desktop.
Save ZechCodes/62258aeeb94809a8c5f829095af09aec to your computer and use it in GitHub Desktop.
Challenge 147 - Emotify Sentence

Challenge 147 - Emotify Sentence

Create a function that changes specific words into emoticons. Given a sentence as a string, replace the words "smile", "grin", "sad", and "mad" with their corresponding emoticons.

word	 emoticon
smile	 :D
grin	 :)
sad	 :(
mad	 :P

Examples

emotify("Make me smile") ➞ "Make me :D"

emotify("Make me grin") ➞ "Make me :)"

emotify("Make me sad") ➞ "Make me :("

Notes

  • Try to solve this without using conditional statements like if/else.
import unittest
def emotify(sentence: str) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual("Make me :D", emotify("Make me smile"))
def test_2(self):
self.assertEqual("Make me :)", emotify("Make me grin"))
def test_3(self):
self.assertEqual("Make me :(", emotify("Make me sad"))
def test_4(self):
self.assertEqual("Make me :P", emotify("Make me mad"))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment