Question

IN PYTHONExercise 4 Build a single chatbot that takes input from the user and behaves in the following way: 1. If the input is a I feel [..] statement, the chatbot responds by asking Why do you feel that way? 2. If the input is a Can you [predicate] question, the chatbot responds by saying Sure, I can [predicatel all day. 3. If the input is a Did you [predicatel question, the chatbot responds by saying No, I didnt [predicate]. 4. If the input is anything else, the chatbot responds by saying Thats interesting. What else is on your mind? (or something to that effect). 5. Have the chatbot loop until the user enters a string containing some variant of quit In 1 Put your code for Exercise 4 here.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def chatbot():
print("--------Welcome to Chatbot-------\n")
while(True):
s = input()#reading input
l = s.split#spliting at space
if(l[0]=="I" and l[1] == "feel"):#mathcing frist two words and displaying corresponding output
print("Why do you feel that way?")
elif(l[0]=="Can" and l[1] == "you"):
i=2
k=""
while(i<len(l)):
k=k+l[i]+" "
i+=1
print("Sure, I can ",k," all day")
elif(l[0]=="Did" and l[1] == "you"):
i=2
k=""
while(i<len(l)):
k=k+l[i]+" "
i+=1
print("No, I didn't ",k)
elif(s.lower()=="quit"):
break
else:
print("That's interesting. What else is on your mind?")
chatbot()

//PLS give a thumbs up if you find this helpful, its helps me alot, thanks


output:

--------Welcome to Chatbot-------
  
I feel you are great   
Why do you feel that way?
Can you sing   
Sure, I can sing all day
Did you do   
No, I didn't do   
you are great
That's interesting. What else is on your mind?   
quit  

1▼ def chatbot(): print(-Welcome to Chatbot--n while(True): s inpu ()#reading input 1 s. split#spliting at space if(1[ojー1 and 1[1] -= feel ): #mathcinq 4. frist two words and displaying print(Why do you feel that way?) i-2 while(i< (1)): elif(1[0]--can and 1[1] you); -- 9 1+-1 print (Sure, I can ,k, all day) if (1[0]Did and 1[1]you): 4. 6 while(i〈lei (1)): 9 1+-1 print (No, I didnt ,k) break print(Thats interesting. What else is on your mind?) elif(s.lower)quit): else: 6 chatbot()

Add a comment
Know the answer?
Add Answer to:
IN PYTHON Exercise 4 Build a single chatbot that takes input from the user and behaves...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [PYTHON] Create a chatbot program in Python: a program that appears to talk intelligently to a...

    [PYTHON] Create a chatbot program in Python: a program that appears to talk intelligently to a human using text. Your program should involve asking the user questions and having the computer respond in a reasonably intelligent fashion based on those answers. For example, here is a sample chat: ChatBot: Welcome, I am Chatbot . What is your name? User: My name is Abby . ChatBot: Hello Abby. How old are you? User: 22. <---- Input ChatBot: That is older than...

  • For this lab, modify the python code below so it will continuously be asking user for...

    For this lab, modify the python code below so it will continuously be asking user for inputs to calculate the interest earned until the user enters number 0 (zero) in principle. Once the user enters any number less or equal to 0 in principle, the program will end. here is my code: # Programming Exercise 3-14 # Local variables p = 0.0 r = 0.0 n = 0.0 t = 0.0 loop = True while loop: p = float(input('\nEnter the...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Create a program in Python that will allow the user to enter a temperature in Fahrenheit...

    Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...

  • [Using Python] I need my code given below to loop the user input, so that you...

    [Using Python] I need my code given below to loop the user input, so that you are asked to input without it stopping after 4 inputs. Code: #A program that converts a hexadecimal number to its decimal value #Define function for hexadecimal to decimal def hexToDec(hexi): result = 0 #For loop to test input for correct values for char in hexi: if 'A' <= char <= 'F' or 'a' <= char <= 'f': if 'a' <= char <= 'f': result...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • In the original flashcard problem, a user can ask the program to show an entry picked...

    In the original flashcard problem, a user can ask the program to show an entry picked randomly from a glossary. When the user presses return, the program shows the definition corresponding to that entry. The user is then given the option of seeing another entry or quitting. A sample session might run as follows: Enter s to show a flashcard and q to quit: s Define: word1 Press return to see the definition definition1 Enter s to show a flashcard...

  • PYTHON I need some basic python homework help! Write a program that prompts the user to...

    PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date. You do not need to validate the input. That means you can assume: the year will be entered as a four-digit number in the range 1900 through 2100 inclusive. the month will be one of the strings "January", "February", . . ., "December". the...

  • I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT