Python Forum
beginner attempting to make chatbot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner attempting to make chatbot
#1
Bug 
hi! i'm pretty new to python- i mean, i've taken classes, but i haven't taken college-level ones or anything. anyway, could you help me debug this bit of my chatbot? thanks!
    elif c == "My computer.":
        print("Does she monitor it?")
        c2 = input()
        if c2 == "Yes.":
            print("So she must know about me.")
        elif c2 == "No.":
            print("Does she know about me?")
            c3 = input()
            if c3 == "Yes.":
                print("Of course. What does she think? About how you have a version of her in your computer?")
            if c3 == "No":
                print("Strange. How?")
when i attempt to test it, my program will not allow me to reply past c2, but i need to have c3 there. what am i doing wrong? thanks! Heart Heart

(by the way, the forum seems to have removed my formatting but the indentation is all correct!)
Yoriz write Feb-02-2022, 10:05 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
You just need to enter "exactly" what the if statement is expecting. In this case "Yes." That's capital "Y" and "period". You would do well to study ways to bullet proof your input. Anyway, here is working code.
print("Does she monitor it?")
c2 = input()
if c2 == "Yes.":
	print("So she must know about me.")
elif c2 == "No.":
	print("Does she know about me?")
c3 = input()
if c3 == "Yes.":
	print("Of course. What does she think? About how you have a version of her in your computer?")
if c3 == "No":
	print("Strange. How?")
Also, try this out:
def check_user_answer (input_string: str) -> str :
	no = ['No', 'no', 'N', 'n']
	yes = ['Yes', 'yes', 'Y', 'y']
	if input_string in no :
		return 'no'
	if input_string in yes :
		return 'yes'
	return 'error'

answer = 'error'
while answer == 'error' :
	test_answer = input ('Does she monitor it? ')
	answer = check_user_answer (test_answer)
if answer == 'yes' :
	print("So she must know about me.")
if answer == 'no' :

	answer = 'error'
	while answer == 'error' :
		test_answer = input ("Does she know about me?")
		answer = check_user_answer (test_answer)
	if answer == 'yes' :
		print('Of course. What does she think? About how', end = '')
		print (' you have a version of her in your computer?')
	if answer == 'no' :
		print ('Strange. How?')
Output:
Does she monitor it? n Does she know about me?y Of course. What does she think? About how you have a version of her in your computer?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Attempting to read keyboard outside of console Jimmy998 5 1,343 Nov-25-2022, 08:17 PM
Last Post: Larz60+
  Help with simple nltk Chatbot Extra 3 1,878 Jan-02-2022, 07:50 AM
Last Post: bepammoifoge
  Python Reminder MSTeams Chatbot ajaymedidi 0 1,140 Sep-16-2021, 07:13 AM
Last Post: ajaymedidi
  Newbie to Python (Attempting to install DJango on a VPS) jarjar95 0 1,524 May-04-2021, 03:51 PM
Last Post: jarjar95
  Generate questions from excel to test my chatbot mcubac08 5 2,858 Sep-01-2020, 06:15 PM
Last Post: mcubac08
  List index out of range error when attempting to make a basic shift code djwilson0495 4 2,981 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Trying to pass an exe filepath to tkinter Chatbot & expecting the chatbot to run it svkroy 0 1,583 Jul-16-2020, 07:46 AM
Last Post: svkroy
  Chatbot metro17 2 10,897 Sep-21-2019, 02:05 PM
Last Post: Larz60+
  Invalid archive error when attempting to install dash bootstrap components meaydemi 0 4,763 Jul-11-2019, 05:49 PM
Last Post: meaydemi
  attempting to run gimp-console from python in windows 10 matteusbeus 3 2,886 Oct-09-2018, 07:05 AM
Last Post: matteusbeus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020