I need my code to output 'hey đ' when the input written is 'hey :)'. Instead it outputs 'h'
def emojiChanger(word):
emoji = " "
for letter in word:
if letter in ":)":
emoji = emoji + "đ"
elif letter in ":(":
emoji = emoji + "âšī¸"
else:
emoji = emoji + letter
return emoji
print(emojiChanger(input('How are you doing? ')))
output:
How are you doing? :)
đ
alternative output: # What I need to fix
How are you doing? hey :)
h
I need it to output: hey đ
It can only go into one of the if
or elif
or else
branches (and it can never go into elif
for :
because the if
already captures that). You need to add stuff to the output string in all of these cases, probably outside the conditional.
However, you are examining one letter at a time, so :
followed by anything will add đ and )
anywhere else in the line will do that too; and (
anywhere will trigger âšī¸
A better approach altogether is perhaps
def emojiChanger(word):
return word.replace(':)', 'đ').replace(':(', 'âšī¸')