Question

In: Computer Science

Python Programming Revise the ChatBot program below. There needs to be one list and one dictionary...

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")

Solutions

Expert Solution

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'
def writeFile(learnedData):
with open("chatBotData.txt","a") as f:
for eachkey in learnedData:
f.write("Name: ")
f.write(eachkey)
f.write("\n")
for eachData in learnedData[eachkey]:
f.write(eachData)
f.write("\n")
f.write("===============================")
f.write("\n")
# 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')

#Have one list and one dictionary
personData = []
person = {}

#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? ')
sport = ""
if(firstHobby.lower() == '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.lower() == '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.lower() == '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.lower() == 'west virginia'):
print("My creator is also from there!")
print(" ")
else:
print("What a lovely state")
print(" ")
#end questions

#Store person details in given dictionary and list
name = firstName + lastName
personData.append("{0:<15}{1}".format("BirthDay:",birthDay))
personData.append("{0:<15}{1}".format("Age:",(currentYear - birthDay)))
personData.append("{0:<15}{1}".format("Play Sports?",firstHobby))
if firstHobby.lower() == "yes":
personData.append("{0:<15}{1}".format("Favorite Sport:",sport))
personData.append("{0:<15}{1}".format("Favorite Animal:",favAnimal))
personData.append("{0:<15}{1}".format("Favorite Season:",favSeason))
personData.append("{0:<15}{1}".format("Have Siblings?",siblings))
personData.append("{0:<15}{1}".format("State Born:",stateBorn))

person[name] = personData
#use writeFile function to store the learned data to file
writeFile(person)
print("Well I thank you for your time but that is all the time we have, thank you for joining me today")

#############################################################

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 :)


Related Solutions

programming in python Design a program that initializes a list of 5 items to zero (use...
programming in python Design a program that initializes a list of 5 items to zero (use repetition operator). It then updates that list with a series of 5 random numbers. The program should find and display the following data: -The lowest number in the list - Average of the numbers stored in the list
Python programming: Instructions: The python program should respond to user input on a command line Below...
Python programming: Instructions: The python program should respond to user input on a command line Below are the four options - if the user input is A, the program will quit -if the user input is B, the program will display the number of times the prompt has been displayed -if the user input is C, will display whatever is stored. -if the user inputs something else, it will store that user input as a string and append it to...
Programming Activity 7 - Guidance ================================= This assignment uses a built-in Python dictionary. It does not...
Programming Activity 7 - Guidance ================================= This assignment uses a built-in Python dictionary. It does not use a dictionary implementation from the textbook collections framework. It does not require any imports/files from the textbook collections framework. This week's "examplePythonDictionary.py" example uses a built-in Python dictionary. Note that the mode() function begins by creating an empty Python dictionary. You must use this dictionary in the following parts. Part 1 ------ In this part you will add entries to the dictionary. Use...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals(if statements) 4. iteration(loops) The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will...
Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric input in the correct range, instead of returning an error. Example: Enter your score: 78 Letter...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT