In: Computer Science
Python Programming
Revise the ChatBot program below. There needs to be one list and one dictionary for the ChatBot to use. Include a read/write function to the program so that the program can learn at least one thing and store the information in a text document.
ChatBot program for revising:
# Meet the chatbot Eve
print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!')
print(' ')
print('Lets get started')
#begin questions
firstName = input('What is your first name?: ')
lastName = input('What is your last name? ')
print("Hi there, ", firstName + lastName, "nice to meet you")
print(" ")
# questions about users favorite things
currentYear = 2020
birthDay = input('What is the year were you born?: ')
birthDay = int(birthDay)
print('Wow! You are already', currentYear - birthDay)
print(" ")
# questions about favorite hobbies
firstHobby = input('Do you play any sports? ')
if(firstHobby == 'Yes'):
sport = input('What sport do you play? ')
print("Nice! I played Soccer and Tennis back when I was human")
print(" ")
else:
print("Bummer, I always liked sports")
print(" ")
favAnimal = input('What is your favorite animal? ')
print("Oooohhh what a cool animal! My favorite is the red panda, such a unique and cute species!")
print(" ")
favSeason = input('What is your favorite season? ')
if(favSeason == 'Fall'):
print("Wow! That is my favorite season also! The colors of the leaves are amazing")
print(" ")
else:
print("Nice! My favorite season is Fall!")
print(" ")
siblings = input('Do you have any siblings in your family? ')
if(siblings == 'Yes'):
print("Very nice, back when I was born a human I grew up with a sister")
print(" ")
else:
print("An only child I see")
print(" ")
stateBorn = input('What state were you born in? ')
if(stateBorn == 'West Virginia'):
print("My creator is also from there!")
print(" ")
else:
print("What a lovely state")
print(" ")
#end questions
print("Well I thank you for your time but that is all the time we have, thank you for joining me today")
Here is the answer for your question in Python Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : I have used one list and one dictioary as specified in the question to store learned data. Created one function to write data to file. Please comment below if you need any explanation of the code.
I have used lower() method at comparisions to check user input as case sensistive because "yes" and "YES" are both same and chatbot should not differentiate results for them.
##########################################################################
CODE :
#read/write file function 'writeFile' #Have one list and one dictionary #begin questions favAnimal = input('What is your favorite animal?
') favSeason = input('What is your favorite season?
') siblings = input('Do you have any siblings in your
family? ') #Store person details in given dictionary and list person[name] = personData |
#############################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code. As python is a language of indentations kindly check the indentations of the code before execution.
#########################################################################
OUTPUT :
File chatBotData.txt will be created in same folder and the data in it will be,
Any doubts regarding this can be explained with pleasure :)