Answer to Question #97187 in Python for brenda flores

Question #97187
A chatbot is a computer program designed to emulate human conversation. For this program you will use if statements, user input, and random numbers to create a basic chatbot.

Here is the scenario: you have decided to start a website. You are creating a prototype to show investors so you can raise money and launch your website.

You should ask the user at least five questions and use if-elif-else statements and give answers depending on how they answer. Some responses should be based on what they type, and some should be based on random numbers.

For example, if they say they are sad, your chatbot might respond “I’m sorry to hear that”.

You could also have a random number generated between 1 and 3 and have a corresponding response depending on the number such as “That is great to hear” or “So interesting”.
1
Expert's answer
2019-10-23T14:31:38-0400
import random


def main():
    greetings = ['Hello', 'Hi', 'Good morning']
    print(random.choice(greetings) + ', welcome to my website\n')

    input('Are you a human? ')
    print('Oh, never mind\n')

    ans = input('How are you doing today? ').lower()
    if 'sad' in ans:
        print('I\'m sorry to hear that\n')
    elif 'well' in ans:
        print('That\'s awesome\n')
    else:
        print('So you are not sad\n')

    ans = input('Would you like to invest in my site? ')
    if ans == 'Yes':
        print('I\'m so sorry, but you can trust me\n')
    else:
        print('Of course, I can receive anonymous payments\n')

    try:
        ans = float(input('How many $$ have you sent? ').strip())
        if ans > 100.0:
            thanks = ('That sounds good', 'Great', 'You are right')
            print(random.choice(thanks) + '\n')
        else:
            print('Why not?\nYou are boring\nDon\'t do that\n'
                  'Feel free to continue\n'.split('\n')[
                      random.randint(-3, -1)] + '\n')
    except ValueError:
        print('Don\'t understand. Have you sent bitcoins?\n')

    input('Do you have any questions? ')
    ans = random.randrange(3)
    if ans == 0:
        print('Bye')
    elif ans == 1:
        print('Nice meeting you')
    elif ans == 2:
        print('I\'m done')
    else:
        print('Please explain it more')


if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

hi
21.10.20, 18:19

noice it worked

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS