![]() |
beginner attempting to make chatbot - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: beginner attempting to make chatbot (/thread-36262.html) |
beginner attempting to make chatbot - MonikaDreemur - Feb-02-2022 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! ![]() ![]() (by the way, the forum seems to have removed my formatting but the indentation is all correct!) RE: beginner attempting to make chatbot - BashBedlam - Feb-02-2022 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?')
|