Hello, I am trying to solve the following problem using python:
Assignment 3: Chatbot
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 an online
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 5 questions ( 5 inputs
required ) and use at least 2 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 Im 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.
My answer that runs, however not accepted as the solution:
import random
name = raw_input("What is your name? ")
print ("Hi there "+name+", nice to meet you.")
age = input("How old are you? ")
if age > 15:
print (str(age)+" is a good age")
print ("You are old enough to drive.")
feeling = raw_input("So, "+name+" how are you today?")
if (feeling == "happy"):
print ("You are "+feeling)
choice = random.randint(1,4)
if(choice == 1):
print ("That is good to hear.")
elif(choice == 2):
print ("So interesting.")
elif(choice == 3):
print ("Great you are happy now.")
else:
print ("Tell me more.")
elif(feeling == "sad"):
print ("You are "+feeling)
choice = random.randint(1,4)
if(choice == 1):
print ("That is not great to hear.")
elif(choice == 2):
print ("Not so interesting.")
elif(choice == 3):
print ("Sad that you are unhappy")
else:
print ("Tell me more.")
favcolour = input("So, "+name+" what is your favourite colour?
")
colours = ["Red","Green","Blue"]
print("Sounds like your favourite colour is " + random.choice(colours))
favplace = input("So, "+name+" what is your favourite place? ")
places = ["Hawaii","Florida","California"]
print("Love that your favourite place is " +
random.choice(places))
print("Sounds interesting.")
print("Well, "+name+", it has been nice chatting with you.")
Points to consider:
Updated Code
import random name = input("What is your name? ") print("Hi there " + name + ", nice to meet you.") age = input("How old are you? ") if age > 15: print(str(age) + " is a good age") print("You are old enough to drive.") feeling = input("So, " + name + " how are you today?") if (feeling == "happy"): print("You are " + feeling) choice = random.randint(1, 4) if (choice == 1): print("That is good to hear.") elif (choice == 2): print("So interesting.") elif (choice == 3): print("Great you are happy now.") else: print("Tell me more.") elif (feeling == "sad"): print("You are " + feeling) choice = random.randint(1, 4) if (choice == 1): print("That is not great to hear.") elif (choice == 2): print("Not so interesting.") elif (choice == 3): print("Sad that you are unhappy") else: print("Tell me more.") else: print("You should not be silent") colours = ["Red", "Green", "Blue"] favcolour = input("So, " + name + " what is your favourite colour?" + str(colours)) if favcolour == colours[0]: print("Its Rosy-Red") elif favcolour == colours[1]: print("Its Parrot-Green") else: print("Its Sky-Blue") print("Sounds like your favourite colour is " + random.choice(colours)) favplace = input("So, " + name + " what is your favourite place? ") places = ["Hawaii", "Florida", "California"] print("Love that your favourite place is " + random.choice(places)) print("Sounds interesting.") print("Well, " + name + ", it has been nice chatting with you.")
Note: Updated Code is in Bold
Code Snippet
Output Snippet
That was a nice
question to answer
Friend, If you have any doubts in understanding do let me know in
the comment section. I will be happy to help you further.
Please like it if you think effort deserves like.
Thanks
Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot...
[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...
Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...
Create a python program to play rock paper scissors using a while loop and if statements. I have started but have gotten stuck in a continuous loop. Please look over my code and help me find where I went wrong. Here it is: import random #Choice weapons=['Rock' ,'Paper' ,'Scissors'] print('Rock, Paper, Scissors!') print('Rock, Paper, Scissors!') print('Shoot!') human=input('Choose Rock, Paper, Scissors, or Quit! ') print('')#Blank Line while human != 'Quit': human_choice=human computer=random.choice(weapons) print(computer) if human==computer: print("It's a tie!") elif human=='Rock': if...
In python this is what I have for task 3, but I don't know how to fix it so that the computer stops picking from the pile once it reaches zero Task 3: Extend the game to have two piles of coins, allow the players to specify which pile they take the coins from, as well as how many coins they take Finish Task 3 and try three test cases import random remaining_coins1 = 22 remaining_coins2 = 22 while 1:...
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...
I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...
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...
Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUYS HELPS ME OUT ON HOW TO TEST A SIMPLE CODE SINCE ITS A GUESSING GAME! THANK YOU. PYTHON import random # here it allows us to use the benefits of the functions random #function 1 which is just a screen organized wordings def screen): screeninstructions () name input("Your Name : ") print('Welcome, name, 'This...