Search code examples
pythonchatbot

trying to create a chat "template" for my chatbot


I am trying to create a template for my chat bot so the chat looks like

carl: my name is carl, what is yours?

user: *some response*

I have no issues with the bot template, but where my issue is coming by is when I try to create the users template, it gives me an error saying "TypeError: unsupported operand type(s) for +: 'function' and 'str'"

# templates
def templates():
    user = myname
    print(user + ':')

# asking your name
def myname():
    print('carl: my name is carl, what is yours?')
    myname = input()
    templates()
    print('carl: nice to meet you ' + myname)

if anyone has any advice, would be greatly appreciated


Solution

  • Try this:

    def templates(user):
        print(user + ': *some response*')
    
    def myname():
        print('carl: my name is carl, what is yours?')
        user = input()
        templates(user)
        print('carl: nice to meet you ' + user)
    
    myname()
    

    Your problem is that you make a function called myname and also make a variable called myname, among other things.