Python Forum

Full Version: beginner attempting to make chatbot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!)
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?