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
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...
Please write in Python code please Write a program that creates a dictionary containing course numbers...
Please write in Python code please Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (key) Room Number (value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. The dictionary should have the following key-value pairs: Course...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT