Replacing some emoticons with emojis in python

13.6k views Asked by At

This is what my code currently looks like. I wanted to change the emoticons to emojis when the user inputs a sentence or word. How do I go by it?

def main():
    sentence = input("Input a Sentence: ")
    convert(sentence)
    print(sentence)


def convert():
    emo1 = ":)"
    emo2 = ":("
    emo1.replace(":)", "")
    emo2.replace(":(", "")


main()
5

There are 5 answers

0
Swaroop Maddu On

You need to add replace emoticons in sentence you sent to the function convert():

def main():
    sentence = input("Input a Sentence: ")
    print(sentence)
    sentence = convert(sentence)
    print(sentence)

def convert(sentence):
    sentence = sentence.replace(":)", "")
    sentence = sentence.replace(":(", "")
    return sentence

main()
0
Jose Luis Garbayo Rey On
def main():
    # user input
    variable_faces = input("Enter your sentence or word: ")
    print(change_faces(variable_faces))


def change_faces(sentence):
    sentence = sentence.replace(":)", "")
    sentence = sentence.replace(":(", "")

    return sentence

main()
1
Arghya Das On
#Declaring the main method
def main():

    x = input('Type: ')
    print(convert(x))

#Creating the convert function to convert emoticons to emojis
def convert(x):

    x=x.replace(':)', '')
    x=x.replace(':(', '')
    return x

#Passing the main method as the output

main()
10
KdPronite On

When you defined convert as a function you forgot to put something inside the parentheses. The variables emo1 and emo2 are unnecessary and are a problem in the code. Below is the code which should work as per what your code was supposed to be.

def convert(emoji):
    emoji1=emoji.replace(':)', '')
    emoji2=emoji1.replace(':(', '')
    return emoji2


def main():
    question=input('What do you want to print: ')
    question1 = convert(question)
    print(question1)


main()
1
Ajay T On

I had a same problem. But this code helped me to resolve this.

  def convert():
        txt=input("enter message ")
        y=txt.replace(":)", "")
        y=y.replace(":(", "")
        print(y)
    convert()