Hello Programmers. It is I, a mere beginner. I require assistance.
#introduction to I.A.N 1.0
print ("Hello, I am I.A.N, your personal Artificial companion! What should I call you?")
name = input()
#Naming
if name == "Ian":
print ("Okay, I will now call you", name,"... wait, we have the same name! How cool is that!")
else:
print ("Okay, I will now call you", name,)
print ("Do you want me to call you by a title?")
yesno = input()
if yesno.casefold() == "yes":
print ("As you wish, what will this title be?")
title = input()
print ("I will now call you by the title of", title,)
else:
print ("As you wish")
title = None
#Questions/responses oh hi.
question = input()
if question == "How are you":
print ("I am great thank you! Might I ask how are you? Are you Happy or Sad?")
answer = input()
if answer == "Happy":
print ("I am glad to hear that,", name or title,)
input()
if answer == "Sad":
print ("Oh, I hope you feel better soon,", title or name,)
question = input()
if question == "Are you real":
print ("Sadly not, but you can still talk to me somehow")
input()
So. I am making a Chatbot, as you do, and have recently fixed a bug regarding the question âAre you real,â not printing as it should. However, I have now come across a new bug.
When I run the program and answer the naming stuff at the top of my script and immediately ask âAre you real,â it throws up an error regarding my âAnswerâ variable:
Traceback (most recent call last):
File "C:\Users\andre\AppData\Local\Programs\Python\Python311\I.A.N.py", line 30, in <module>
if answer == "Happy":
NameError: name 'answer' is not defined
I assume Its giving me this error as in the code for the âAre you real,â I have not mentioned an âAnswerâ Variable and It wants one. Unfortunately.
I think itâs reading the code top to bottom and as i have used the Variable âQuestionâ again for âAre you real,â It gets confused and tries to run the code for âHow are you,â
I would much appreciate any help with this as if it can be fixed, my Chatbot will almost be ready to add more things and features to.
Thank you, Andrew Rowland