[{"data":1,"prerenderedAt":2116},["ShallowReactive",2],{"doc-\u002Fexamples\u002Fpython-simple-chatbot-example":3},{"id":4,"title":5,"body":6,"description":2109,"extension":2110,"meta":2111,"navigation":211,"path":2112,"seo":2113,"stem":2114,"__hash__":2115},"content\u002Fexamples\u002Fpython-simple-chatbot-example.md","Python Simple Chatbot Example",{"type":7,"value":8,"toc":2076},"minimark",[9,13,17,20,51,54,66,71,74,85,88,92,95,148,152,155,407,412,417,450,453,461,474,480,486,492,496,528,531,551,554,561,582,589,598,719,722,753,760,767,776,784,787,791,794,802,805,823,827,830,833,854,859,862,873,877,880,1137,1146,1149,1171,1178,1182,1185,1192,1195,1218,1221,1251,1256,1266,1268,1303,1305,1340,1352,1363,1365,1399,1401,1435,1445,1452,1454,1497,1499,1538,1543,1547,1554,1568,1571,1601,1605,1608,1641,1645,1648,1651,1671,1674,1889,1892,1896,1899,1927,1930,1941,1948,1952,1956,1959,1968,1971,1975,1981,1985,1994,1998,2007,2011,2052,2055,2058,2069,2072],[10,11,5],"h1",{"id":12},"python-simple-chatbot-example",[14,15,16],"p",{},"This beginner-friendly example shows how to build a very simple chatbot in Python.",[14,18,19],{},"It is a small terminal program that:",[21,22,23,27,42,45],"ul",{},[24,25,26],"li",{},"reads text from the user",[24,28,29,30,34,35,38,39],{},"checks that text with ",[31,32,33],"code",{},"if",", ",[31,36,37],{},"elif",", and ",[31,40,41],{},"else",[24,43,44],{},"prints a fixed reply",[24,46,47,48],{},"keeps running in a loop until the user types ",[31,49,50],{},"bye",[14,52,53],{},"This project is useful for practicing basic Python skills in one place.",[14,55,56,57,61,62,65],{},"Important: this is ",[58,59,60],"strong",{},"not"," an AI chatbot. It is a ",[58,63,64],{},"rule-based chatbot",", which means it only responds to messages you have programmed.",[67,68,70],"h2",{"id":69},"what-this-example-builds","What this example builds",[14,72,73],{},"This example creates:",[21,75,76,79,82],{},[24,77,78],{},"A text-based chatbot that runs in the terminal",[24,80,81],{},"A bot that reads user input and replies with fixed answers",[24,83,84],{},"A small project for practicing beginner Python basics",[14,86,87],{},"The chatbot does not think or learn. It just compares the user's message to known text and returns a matching response.",[67,89,91],{"id":90},"what-you-will-learn","What you will learn",[14,93,94],{},"By building this chatbot, you will practice:",[21,96,97,108,120,131,137],{},[24,98,99,100,107],{},"How to use ",[101,102,104],"a",{"href":103},"\u002Freference\u002Fpython-input-function-explained\u002F",[31,105,106],{},"input()"," to get text from the user",[24,109,99,110,119],{},[101,111,113,34,115,38,117],{"href":112},"\u002Flearn\u002Fpython-if-else-and-elif-explained\u002F",[31,114,33],{},[31,116,37],{},[31,118,41],{}," to choose a reply",[24,121,122,123,130],{},"How to use a ",[101,124,126,129],{"href":125},"\u002Flearn\u002Fpython-while-loops-explained\u002F",[31,127,128],{},"while"," loop"," to keep the chatbot running",[24,132,133,134],{},"How to stop the program with ",[31,135,136],{},"break",[24,138,139,140,143,144,147],{},"How ",[31,141,142],{},"lower()"," and ",[31,145,146],{},"strip()"," make input easier to match",[67,149,151],{"id":150},"basic-chatbot-code-walkthrough","Basic chatbot code walkthrough",[14,153,154],{},"Here is the full minimal chatbot script:",[156,157,162],"pre",{"className":158,"code":159,"language":160,"meta":161,"style":161},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","print(\"Simple Chatbot\")\nprint(\"Type 'bye' to stop.\")\n\nwhile True:\n    message = input(\"You: \").lower().strip()\n\n    if message == \"hello\":\n        print(\"Bot: Hi!\")\n    elif message == \"how are you\":\n        print(\"Bot: I am doing well.\")\n    elif message == \"bye\":\n        print(\"Bot: Goodbye!\")\n        break\n    else:\n        print(\"Bot: Sorry, I don't understand.\")\n","python","",[31,163,164,190,206,213,226,265,270,292,309,328,344,361,377,383,391],{"__ignoreMap":161},[165,166,169,173,177,181,185,187],"span",{"class":167,"line":168},"line",1,[165,170,172],{"class":171},"sptTA","print",[165,174,176],{"class":175},"sP7_E","(",[165,178,180],{"class":179},"sjJ54","\"",[165,182,184],{"class":183},"s_sjI","Simple Chatbot",[165,186,180],{"class":179},[165,188,189],{"class":175},")\n",[165,191,193,195,197,199,202,204],{"class":167,"line":192},2,[165,194,172],{"class":171},[165,196,176],{"class":175},[165,198,180],{"class":179},[165,200,201],{"class":183},"Type 'bye' to stop.",[165,203,180],{"class":179},[165,205,189],{"class":175},[165,207,209],{"class":167,"line":208},3,[165,210,212],{"emptyLinePlaceholder":211},true,"\n",[165,214,216,219,223],{"class":167,"line":215},4,[165,217,128],{"class":218},"sVHd0",[165,220,222],{"class":221},"s39Yj"," True",[165,224,225],{"class":175},":\n",[165,227,229,233,237,240,242,244,247,249,252,256,259,262],{"class":167,"line":228},5,[165,230,232],{"class":231},"su5hD","    message ",[165,234,236],{"class":235},"smGrS","=",[165,238,239],{"class":171}," input",[165,241,176],{"class":175},[165,243,180],{"class":179},[165,245,246],{"class":183},"You: ",[165,248,180],{"class":179},[165,250,251],{"class":175},").",[165,253,255],{"class":254},"slqww","lower",[165,257,258],{"class":175},"().",[165,260,261],{"class":254},"strip",[165,263,264],{"class":175},"()\n",[165,266,268],{"class":167,"line":267},6,[165,269,212],{"emptyLinePlaceholder":211},[165,271,273,276,279,282,285,288,290],{"class":167,"line":272},7,[165,274,275],{"class":218},"    if",[165,277,278],{"class":231}," message ",[165,280,281],{"class":235},"==",[165,283,284],{"class":179}," \"",[165,286,287],{"class":183},"hello",[165,289,180],{"class":179},[165,291,225],{"class":175},[165,293,295,298,300,302,305,307],{"class":167,"line":294},8,[165,296,297],{"class":171},"        print",[165,299,176],{"class":175},[165,301,180],{"class":179},[165,303,304],{"class":183},"Bot: Hi!",[165,306,180],{"class":179},[165,308,189],{"class":175},[165,310,312,315,317,319,321,324,326],{"class":167,"line":311},9,[165,313,314],{"class":218},"    elif",[165,316,278],{"class":231},[165,318,281],{"class":235},[165,320,284],{"class":179},[165,322,323],{"class":183},"how are you",[165,325,180],{"class":179},[165,327,225],{"class":175},[165,329,331,333,335,337,340,342],{"class":167,"line":330},10,[165,332,297],{"class":171},[165,334,176],{"class":175},[165,336,180],{"class":179},[165,338,339],{"class":183},"Bot: I am doing well.",[165,341,180],{"class":179},[165,343,189],{"class":175},[165,345,347,349,351,353,355,357,359],{"class":167,"line":346},11,[165,348,314],{"class":218},[165,350,278],{"class":231},[165,352,281],{"class":235},[165,354,284],{"class":179},[165,356,50],{"class":183},[165,358,180],{"class":179},[165,360,225],{"class":175},[165,362,364,366,368,370,373,375],{"class":167,"line":363},12,[165,365,297],{"class":171},[165,367,176],{"class":175},[165,369,180],{"class":179},[165,371,372],{"class":183},"Bot: Goodbye!",[165,374,180],{"class":179},[165,376,189],{"class":175},[165,378,380],{"class":167,"line":379},13,[165,381,382],{"class":218},"        break\n",[165,384,386,389],{"class":167,"line":385},14,[165,387,388],{"class":218},"    else",[165,390,225],{"class":175},[165,392,394,396,398,400,403,405],{"class":167,"line":393},15,[165,395,297],{"class":171},[165,397,176],{"class":175},[165,399,180],{"class":179},[165,401,402],{"class":183},"Bot: Sorry, I don't understand.",[165,404,180],{"class":179},[165,406,189],{"class":175},[408,409,411],"h3",{"id":410},"how-this-code-works","How this code works",[413,414,416],"h4",{"id":415},"_1-the-program-starts-with-two-messages","1. The program starts with two messages",[156,418,420],{"className":158,"code":419,"language":160,"meta":161,"style":161},"print(\"Simple Chatbot\")\nprint(\"Type 'bye' to stop.\")\n",[31,421,422,436],{"__ignoreMap":161},[165,423,424,426,428,430,432,434],{"class":167,"line":168},[165,425,172],{"class":171},[165,427,176],{"class":175},[165,429,180],{"class":179},[165,431,184],{"class":183},[165,433,180],{"class":179},[165,435,189],{"class":175},[165,437,438,440,442,444,446,448],{"class":167,"line":192},[165,439,172],{"class":171},[165,441,176],{"class":175},[165,443,180],{"class":179},[165,445,201],{"class":183},[165,447,180],{"class":179},[165,449,189],{"class":175},[14,451,452],{},"These lines show a title and tell the user how to exit the chatbot.",[413,454,456,457,460],{"id":455},"_2-the-while-true-loop-keeps-the-chatbot-running","2. The ",[31,458,459],{},"while True"," loop keeps the chatbot running",[156,462,464],{"className":158,"code":463,"language":160,"meta":161,"style":161},"while True:\n",[31,465,466],{"__ignoreMap":161},[165,467,468,470,472],{"class":167,"line":168},[165,469,128],{"class":218},[165,471,222],{"class":221},[165,473,225],{"class":175},[14,475,476,477,479],{},"A ",[31,478,459],{}," loop runs forever unless something stops it.",[14,481,482,483,485],{},"In this chatbot, the loop keeps asking for messages until the user types ",[31,484,50],{},".",[14,487,488,489,485],{},"If you are new to loops, see ",[101,490,491],{"href":125},"Python while loops explained",[413,493,495],{"id":494},"_3-the-chatbot-reads-user-input","3. The chatbot reads user input",[156,497,499],{"className":158,"code":498,"language":160,"meta":161,"style":161},"message = input(\"You: \").lower().strip()\n",[31,500,501],{"__ignoreMap":161},[165,502,503,506,508,510,512,514,516,518,520,522,524,526],{"class":167,"line":168},[165,504,505],{"class":231},"message ",[165,507,236],{"class":235},[165,509,239],{"class":171},[165,511,176],{"class":175},[165,513,180],{"class":179},[165,515,246],{"class":183},[165,517,180],{"class":179},[165,519,251],{"class":175},[165,521,255],{"class":254},[165,523,258],{"class":175},[165,525,261],{"class":254},[165,527,264],{"class":175},[14,529,530],{},"This line does three things:",[21,532,533,539,545],{},[24,534,535,538],{},[31,536,537],{},"input(\"You: \")"," waits for the user to type something",[24,540,541,544],{},[31,542,543],{},".lower()"," changes the text to lowercase",[24,546,547,550],{},[31,548,549],{},".strip()"," removes extra spaces at the beginning and end",[14,552,553],{},"This helps the chatbot match input more easily.",[14,555,556,557,560],{},"For example, these all become ",[31,558,559],{},"\"hello\"",":",[21,562,563,567,572,577],{},[24,564,565],{},[31,566,287],{},[24,568,569],{},[31,570,571],{},"Hello",[24,573,574],{},[31,575,576],{},"HELLO",[24,578,579],{},[31,580,581],{}," hello ",[14,583,584,585,485],{},"If you want more practice with user input, read ",[101,586,588],{"href":587},"\u002Fhow-to\u002Fhow-to-get-user-input-in-python\u002F","how to get user input in Python",[413,590,592,593,143,595,597],{"id":591},"_4-the-if-and-elif-statements-choose-the-reply","4. The ",[31,594,33],{},[31,596,37],{}," statements choose the reply",[156,599,601],{"className":158,"code":600,"language":160,"meta":161,"style":161},"if message == \"hello\":\n    print(\"Bot: Hi!\")\nelif message == \"how are you\":\n    print(\"Bot: I am doing well.\")\nelif message == \"bye\":\n    print(\"Bot: Goodbye!\")\n    break\nelse:\n    print(\"Bot: Sorry, I don't understand.\")\n",[31,602,603,619,634,650,664,680,694,699,705],{"__ignoreMap":161},[165,604,605,607,609,611,613,615,617],{"class":167,"line":168},[165,606,33],{"class":218},[165,608,278],{"class":231},[165,610,281],{"class":235},[165,612,284],{"class":179},[165,614,287],{"class":183},[165,616,180],{"class":179},[165,618,225],{"class":175},[165,620,621,624,626,628,630,632],{"class":167,"line":192},[165,622,623],{"class":171},"    print",[165,625,176],{"class":175},[165,627,180],{"class":179},[165,629,304],{"class":183},[165,631,180],{"class":179},[165,633,189],{"class":175},[165,635,636,638,640,642,644,646,648],{"class":167,"line":208},[165,637,37],{"class":218},[165,639,278],{"class":231},[165,641,281],{"class":235},[165,643,284],{"class":179},[165,645,323],{"class":183},[165,647,180],{"class":179},[165,649,225],{"class":175},[165,651,652,654,656,658,660,662],{"class":167,"line":215},[165,653,623],{"class":171},[165,655,176],{"class":175},[165,657,180],{"class":179},[165,659,339],{"class":183},[165,661,180],{"class":179},[165,663,189],{"class":175},[165,665,666,668,670,672,674,676,678],{"class":167,"line":228},[165,667,37],{"class":218},[165,669,278],{"class":231},[165,671,281],{"class":235},[165,673,284],{"class":179},[165,675,50],{"class":183},[165,677,180],{"class":179},[165,679,225],{"class":175},[165,681,682,684,686,688,690,692],{"class":167,"line":267},[165,683,623],{"class":171},[165,685,176],{"class":175},[165,687,180],{"class":179},[165,689,372],{"class":183},[165,691,180],{"class":179},[165,693,189],{"class":175},[165,695,696],{"class":167,"line":272},[165,697,698],{"class":218},"    break\n",[165,700,701,703],{"class":167,"line":294},[165,702,41],{"class":218},[165,704,225],{"class":175},[165,706,707,709,711,713,715,717],{"class":167,"line":311},[165,708,623],{"class":171},[165,710,176],{"class":175},[165,712,180],{"class":179},[165,714,402],{"class":183},[165,716,180],{"class":179},[165,718,189],{"class":175},[14,720,721],{},"This is the chatbot's decision logic:",[21,723,724,733,741,747],{},[24,725,726,727,729,730],{},"If the message is ",[31,728,559],{},", the bot says ",[31,731,732],{},"Hi!",[24,734,726,735,729,738],{},[31,736,737],{},"\"how are you\"",[31,739,740],{},"I am doing well.",[24,742,726,743,746],{},[31,744,745],{},"\"bye\"",", the bot says goodbye and stops",[24,748,749,750,752],{},"If nothing matches, the ",[31,751,41],{}," block runs",[14,754,755,756,485],{},"If you need a refresher, see ",[101,757,759],{"href":758},"\u002Flearn\u002Fpython-if-statements-explained\u002F","Python if statements explained",[413,761,763,764,766],{"id":762},"_5-the-break-statement-ends-the-loop","5. The ",[31,765,136],{}," statement ends the loop",[156,768,770],{"className":158,"code":769,"language":160,"meta":161,"style":161},"break\n",[31,771,772],{"__ignoreMap":161},[165,773,774],{"class":167,"line":168},[165,775,769],{"class":218},[14,777,778,780,781,783],{},[31,779,136],{}," immediately stops the ",[31,782,459],{}," loop.",[14,785,786],{},"Without it, the chatbot would keep running forever.",[67,788,790],{"id":789},"expected-output","Expected output",[14,792,793],{},"Here is one example conversation:",[156,795,800],{"className":796,"code":798,"language":799,"meta":161},[797],"language-text","Simple Chatbot\nType 'bye' to stop.\nYou: hello\nBot: Hi!\nYou: what is your favorite color\nBot: Sorry, I don't understand.\nYou: bye\nBot: Goodbye!\n","text",[31,801,798],{"__ignoreMap":161},[14,803,804],{},"This example shows:",[21,806,807,812,818],{},[24,808,809,810],{},"a known message: ",[31,811,287],{},[24,813,814,815],{},"an unknown message: ",[31,816,817],{},"what is your favorite color",[24,819,820,821],{},"the exit message: ",[31,822,50],{},[67,824,826],{"id":825},"how-the-chatbot-logic-works","How the chatbot logic works",[14,828,829],{},"The program handles one message at a time.",[14,831,832],{},"The logic is simple:",[834,835,836,839,845,848,851],"ol",{},[24,837,838],{},"Ask the user for a message",[24,840,841,842],{},"Clean the text with ",[31,843,844],{},"lower().strip()",[24,846,847],{},"Compare the message with known phrases",[24,849,850],{},"Print the matching response",[24,852,853],{},"If no phrase matches, use the fallback reply",[14,855,856,857,485],{},"This kind of chatbot is called a ",[58,858,64],{},[14,860,861],{},"It works well for learning because:",[21,863,864,867,870],{},[24,865,866],{},"the logic is easy to follow",[24,868,869],{},"each response is predictable",[24,871,872],{},"you can add new replies step by step",[67,874,876],{"id":875},"improved-version-with-more-responses","Improved version with more responses",[14,878,879],{},"Here is a slightly larger version with a few more commands:",[156,881,883],{"className":158,"code":882,"language":160,"meta":161,"style":161},"print(\"Simple Chatbot\")\nprint(\"Type 'bye' to stop.\")\n\nwhile True:\n    message = input(\"You: \").lower().strip()\n\n    if message == \"hello\":\n        print(\"Bot: Hi!\")\n    elif message == \"how are you\":\n        print(\"Bot: I am doing well.\")\n    elif message == \"name\":\n        print(\"Bot: I am a simple Python chatbot.\")\n    elif message == \"help\":\n        print(\"Bot: Try typing hello, how are you, name, or bye.\")\n    elif message == \"bye\":\n        print(\"Bot: Goodbye!\")\n        break\n    else:\n        print(\"Bot: Sorry, I don't understand.\")\n",[31,884,885,899,913,917,925,951,955,971,985,1001,1015,1032,1047,1064,1079,1095,1110,1115,1122],{"__ignoreMap":161},[165,886,887,889,891,893,895,897],{"class":167,"line":168},[165,888,172],{"class":171},[165,890,176],{"class":175},[165,892,180],{"class":179},[165,894,184],{"class":183},[165,896,180],{"class":179},[165,898,189],{"class":175},[165,900,901,903,905,907,909,911],{"class":167,"line":192},[165,902,172],{"class":171},[165,904,176],{"class":175},[165,906,180],{"class":179},[165,908,201],{"class":183},[165,910,180],{"class":179},[165,912,189],{"class":175},[165,914,915],{"class":167,"line":208},[165,916,212],{"emptyLinePlaceholder":211},[165,918,919,921,923],{"class":167,"line":215},[165,920,128],{"class":218},[165,922,222],{"class":221},[165,924,225],{"class":175},[165,926,927,929,931,933,935,937,939,941,943,945,947,949],{"class":167,"line":228},[165,928,232],{"class":231},[165,930,236],{"class":235},[165,932,239],{"class":171},[165,934,176],{"class":175},[165,936,180],{"class":179},[165,938,246],{"class":183},[165,940,180],{"class":179},[165,942,251],{"class":175},[165,944,255],{"class":254},[165,946,258],{"class":175},[165,948,261],{"class":254},[165,950,264],{"class":175},[165,952,953],{"class":167,"line":267},[165,954,212],{"emptyLinePlaceholder":211},[165,956,957,959,961,963,965,967,969],{"class":167,"line":272},[165,958,275],{"class":218},[165,960,278],{"class":231},[165,962,281],{"class":235},[165,964,284],{"class":179},[165,966,287],{"class":183},[165,968,180],{"class":179},[165,970,225],{"class":175},[165,972,973,975,977,979,981,983],{"class":167,"line":294},[165,974,297],{"class":171},[165,976,176],{"class":175},[165,978,180],{"class":179},[165,980,304],{"class":183},[165,982,180],{"class":179},[165,984,189],{"class":175},[165,986,987,989,991,993,995,997,999],{"class":167,"line":311},[165,988,314],{"class":218},[165,990,278],{"class":231},[165,992,281],{"class":235},[165,994,284],{"class":179},[165,996,323],{"class":183},[165,998,180],{"class":179},[165,1000,225],{"class":175},[165,1002,1003,1005,1007,1009,1011,1013],{"class":167,"line":330},[165,1004,297],{"class":171},[165,1006,176],{"class":175},[165,1008,180],{"class":179},[165,1010,339],{"class":183},[165,1012,180],{"class":179},[165,1014,189],{"class":175},[165,1016,1017,1019,1021,1023,1025,1028,1030],{"class":167,"line":346},[165,1018,314],{"class":218},[165,1020,278],{"class":231},[165,1022,281],{"class":235},[165,1024,284],{"class":179},[165,1026,1027],{"class":183},"name",[165,1029,180],{"class":179},[165,1031,225],{"class":175},[165,1033,1034,1036,1038,1040,1043,1045],{"class":167,"line":363},[165,1035,297],{"class":171},[165,1037,176],{"class":175},[165,1039,180],{"class":179},[165,1041,1042],{"class":183},"Bot: I am a simple Python chatbot.",[165,1044,180],{"class":179},[165,1046,189],{"class":175},[165,1048,1049,1051,1053,1055,1057,1060,1062],{"class":167,"line":379},[165,1050,314],{"class":218},[165,1052,278],{"class":231},[165,1054,281],{"class":235},[165,1056,284],{"class":179},[165,1058,1059],{"class":183},"help",[165,1061,180],{"class":179},[165,1063,225],{"class":175},[165,1065,1066,1068,1070,1072,1075,1077],{"class":167,"line":385},[165,1067,297],{"class":171},[165,1069,176],{"class":175},[165,1071,180],{"class":179},[165,1073,1074],{"class":183},"Bot: Try typing hello, how are you, name, or bye.",[165,1076,180],{"class":179},[165,1078,189],{"class":175},[165,1080,1081,1083,1085,1087,1089,1091,1093],{"class":167,"line":393},[165,1082,314],{"class":218},[165,1084,278],{"class":231},[165,1086,281],{"class":235},[165,1088,284],{"class":179},[165,1090,50],{"class":183},[165,1092,180],{"class":179},[165,1094,225],{"class":175},[165,1096,1098,1100,1102,1104,1106,1108],{"class":167,"line":1097},16,[165,1099,297],{"class":171},[165,1101,176],{"class":175},[165,1103,180],{"class":179},[165,1105,372],{"class":183},[165,1107,180],{"class":179},[165,1109,189],{"class":175},[165,1111,1113],{"class":167,"line":1112},17,[165,1114,382],{"class":218},[165,1116,1118,1120],{"class":167,"line":1117},18,[165,1119,388],{"class":218},[165,1121,225],{"class":175},[165,1123,1125,1127,1129,1131,1133,1135],{"class":167,"line":1124},19,[165,1126,297],{"class":171},[165,1128,176],{"class":175},[165,1130,180],{"class":179},[165,1132,402],{"class":183},[165,1134,180],{"class":179},[165,1136,189],{"class":175},[14,1138,1139,1140,1142,1143,1145],{},"This version uses the same ",[31,1141,33],{},"\u002F",[31,1144,37],{}," structure, so it should still feel familiar.",[14,1147,1148],{},"You can test messages like:",[21,1150,1151,1155,1159,1163,1167],{},[24,1152,1153],{},[31,1154,287],{},[24,1156,1157],{},[31,1158,323],{},[24,1160,1161],{},[31,1162,1027],{},[24,1164,1165],{},[31,1166,1059],{},[24,1168,1169],{},[31,1170,50],{},[14,1172,1173,1174,485],{},"Later, you could move these replies into a dictionary for cleaner code. If you want to learn that next, see ",[101,1175,1177],{"href":1176},"\u002Flearn\u002Fpython-dictionaries-explained\u002F","Python dictionaries explained",[67,1179,1181],{"id":1180},"common-beginner-mistakes","Common beginner mistakes",[14,1183,1184],{},"Here are some common problems beginners run into with this project.",[408,1186,1188,1189],{"id":1187},"forgetting-parentheses-after-input","Forgetting parentheses after ",[31,1190,1191],{},"input",[14,1193,1194],{},"Wrong:",[156,1196,1198],{"className":158,"code":1197,"language":160,"meta":161,"style":161},"message = input.lower().strip()\n",[31,1199,1200],{"__ignoreMap":161},[165,1201,1202,1204,1206,1208,1210,1212,1214,1216],{"class":167,"line":168},[165,1203,505],{"class":231},[165,1205,236],{"class":235},[165,1207,239],{"class":171},[165,1209,485],{"class":175},[165,1211,255],{"class":254},[165,1213,258],{"class":175},[165,1215,261],{"class":254},[165,1217,264],{"class":175},[14,1219,1220],{},"Correct:",[156,1222,1223],{"className":158,"code":498,"language":160,"meta":161,"style":161},[31,1224,1225],{"__ignoreMap":161},[165,1226,1227,1229,1231,1233,1235,1237,1239,1241,1243,1245,1247,1249],{"class":167,"line":168},[165,1228,505],{"class":231},[165,1230,236],{"class":235},[165,1232,239],{"class":171},[165,1234,176],{"class":175},[165,1236,180],{"class":179},[165,1238,246],{"class":183},[165,1240,180],{"class":179},[165,1242,251],{"class":175},[165,1244,255],{"class":254},[165,1246,258],{"class":175},[165,1248,261],{"class":254},[165,1250,264],{"class":175},[14,1252,1253,1255],{},[31,1254,1191],{}," is a function, so it needs parentheses.",[408,1257,1259,1260,1262,1263,1265],{"id":1258},"using-instead-of-in-conditions","Using ",[31,1261,236],{}," instead of ",[31,1264,281],{}," in conditions",[14,1267,1194],{},[156,1269,1271],{"className":158,"code":1270,"language":160,"meta":161,"style":161},"if message = \"hello\":\n    print(\"Bot: Hi!\")\n",[31,1272,1273,1289],{"__ignoreMap":161},[165,1274,1275,1277,1279,1281,1283,1285,1287],{"class":167,"line":168},[165,1276,33],{"class":218},[165,1278,278],{"class":231},[165,1280,236],{"class":235},[165,1282,284],{"class":179},[165,1284,287],{"class":183},[165,1286,180],{"class":179},[165,1288,225],{"class":175},[165,1290,1291,1293,1295,1297,1299,1301],{"class":167,"line":192},[165,1292,623],{"class":171},[165,1294,176],{"class":175},[165,1296,180],{"class":179},[165,1298,304],{"class":183},[165,1300,180],{"class":179},[165,1302,189],{"class":175},[14,1304,1220],{},[156,1306,1308],{"className":158,"code":1307,"language":160,"meta":161,"style":161},"if message == \"hello\":\n    print(\"Bot: Hi!\")\n",[31,1309,1310,1326],{"__ignoreMap":161},[165,1311,1312,1314,1316,1318,1320,1322,1324],{"class":167,"line":168},[165,1313,33],{"class":218},[165,1315,278],{"class":231},[165,1317,281],{"class":235},[165,1319,284],{"class":179},[165,1321,287],{"class":183},[165,1323,180],{"class":179},[165,1325,225],{"class":175},[165,1327,1328,1330,1332,1334,1336,1338],{"class":167,"line":192},[165,1329,623],{"class":171},[165,1331,176],{"class":175},[165,1333,180],{"class":179},[165,1335,304],{"class":183},[165,1337,180],{"class":179},[165,1339,189],{"class":175},[21,1341,1342,1347],{},[24,1343,1344,1346],{},[31,1345,236],{}," assigns a value",[24,1348,1349,1351],{},[31,1350,281],{}," compares values",[408,1353,1355,1356,34,1358,1360,1361],{"id":1354},"forgetting-the-colon-after-if-elif-or-else","Forgetting the colon after ",[31,1357,33],{},[31,1359,37],{},", or ",[31,1362,41],{},[14,1364,1194],{},[156,1366,1368],{"className":158,"code":1367,"language":160,"meta":161,"style":161},"if message == \"hello\"\n    print(\"Bot: Hi!\")\n",[31,1369,1370,1385],{"__ignoreMap":161},[165,1371,1372,1374,1376,1378,1380,1382],{"class":167,"line":168},[165,1373,33],{"class":218},[165,1375,278],{"class":231},[165,1377,281],{"class":235},[165,1379,284],{"class":179},[165,1381,287],{"class":183},[165,1383,1384],{"class":179},"\"\n",[165,1386,1387,1389,1391,1393,1395,1397],{"class":167,"line":192},[165,1388,623],{"class":171},[165,1390,176],{"class":175},[165,1392,180],{"class":179},[165,1394,304],{"class":183},[165,1396,180],{"class":179},[165,1398,189],{"class":175},[14,1400,1220],{},[156,1402,1403],{"className":158,"code":1307,"language":160,"meta":161,"style":161},[31,1404,1405,1421],{"__ignoreMap":161},[165,1406,1407,1409,1411,1413,1415,1417,1419],{"class":167,"line":168},[165,1408,33],{"class":218},[165,1410,278],{"class":231},[165,1412,281],{"class":235},[165,1414,284],{"class":179},[165,1416,287],{"class":183},[165,1418,180],{"class":179},[165,1420,225],{"class":175},[165,1422,1423,1425,1427,1429,1431,1433],{"class":167,"line":192},[165,1424,623],{"class":171},[165,1426,176],{"class":175},[165,1428,180],{"class":179},[165,1430,304],{"class":183},[165,1432,180],{"class":179},[165,1434,189],{"class":175},[14,1436,1437,1438,485],{},"A missing colon causes a syntax error. See ",[101,1439,1441,1442],{"href":1440},"\u002Ferrors\u002Fsyntaxerror-invalid-syntax-fix\u002F","how to fix ",[31,1443,1444],{},"SyntaxError: invalid syntax",[408,1446,1448,1449,1451],{"id":1447},"writing-break-outside-the-loop","Writing ",[31,1450,136],{}," outside the loop",[14,1453,1194],{},[156,1455,1457],{"className":158,"code":1456,"language":160,"meta":161,"style":161},"if message == \"bye\":\n    print(\"Bot: Goodbye!\")\n\nbreak\n",[31,1458,1459,1475,1489,1493],{"__ignoreMap":161},[165,1460,1461,1463,1465,1467,1469,1471,1473],{"class":167,"line":168},[165,1462,33],{"class":218},[165,1464,278],{"class":231},[165,1466,281],{"class":235},[165,1468,284],{"class":179},[165,1470,50],{"class":183},[165,1472,180],{"class":179},[165,1474,225],{"class":175},[165,1476,1477,1479,1481,1483,1485,1487],{"class":167,"line":192},[165,1478,623],{"class":171},[165,1480,176],{"class":175},[165,1482,180],{"class":179},[165,1484,372],{"class":183},[165,1486,180],{"class":179},[165,1488,189],{"class":175},[165,1490,1491],{"class":167,"line":208},[165,1492,212],{"emptyLinePlaceholder":211},[165,1494,1495],{"class":167,"line":215},[165,1496,769],{"class":218},[14,1498,1220],{},[156,1500,1502],{"className":158,"code":1501,"language":160,"meta":161,"style":161},"if message == \"bye\":\n    print(\"Bot: Goodbye!\")\n    break\n",[31,1503,1504,1520,1534],{"__ignoreMap":161},[165,1505,1506,1508,1510,1512,1514,1516,1518],{"class":167,"line":168},[165,1507,33],{"class":218},[165,1509,278],{"class":231},[165,1511,281],{"class":235},[165,1513,284],{"class":179},[165,1515,50],{"class":183},[165,1517,180],{"class":179},[165,1519,225],{"class":175},[165,1521,1522,1524,1526,1528,1530,1532],{"class":167,"line":192},[165,1523,623],{"class":171},[165,1525,176],{"class":175},[165,1527,180],{"class":179},[165,1529,372],{"class":183},[165,1531,180],{"class":179},[165,1533,189],{"class":175},[165,1535,1536],{"class":167,"line":208},[165,1537,698],{"class":218},[14,1539,1540,1542],{},[31,1541,136],{}," must be inside a loop.",[408,1544,1546],{"id":1545},"not-handling-uppercase-letters-or-extra-spaces","Not handling uppercase letters or extra spaces",[14,1548,1549,1550,1553],{},"If you do not use ",[31,1551,1552],{},".lower().strip()",", the chatbot may fail to match input like:",[21,1555,1556,1560,1564],{},[24,1557,1558],{},[31,1559,571],{},[24,1561,1562],{},[31,1563,576],{},[24,1565,1566],{},[31,1567,581],{},[14,1569,1570],{},"That is why this line is helpful:",[156,1572,1573],{"className":158,"code":498,"language":160,"meta":161,"style":161},[31,1574,1575],{"__ignoreMap":161},[165,1576,1577,1579,1581,1583,1585,1587,1589,1591,1593,1595,1597,1599],{"class":167,"line":168},[165,1578,505],{"class":231},[165,1580,236],{"class":235},[165,1582,239],{"class":171},[165,1584,176],{"class":175},[165,1586,180],{"class":179},[165,1588,246],{"class":183},[165,1590,180],{"class":179},[165,1592,251],{"class":175},[165,1594,255],{"class":254},[165,1596,258],{"class":175},[165,1598,261],{"class":254},[165,1600,264],{"class":175},[408,1602,1604],{"id":1603},"other-common-causes","Other common causes",[14,1606,1607],{},"You may also run into these problems:",[21,1609,1610,1616,1619,1631,1638],{},[24,1611,1612,1613,1615],{},"The program never exits because there is no ",[31,1614,136],{}," condition",[24,1617,1618],{},"The chatbot does not recognize input because the text case does not match",[24,1620,476,1621,1624,1625,34,1627,1360,1629],{},[31,1622,1623],{},"SyntaxError"," happens because a colon is missing after ",[31,1626,33],{},[31,1628,37],{},[31,1630,41],{},[24,1632,1633,1634,1637],{},"An ",[31,1635,1636],{},"IndentationError"," happens because blocks are not indented correctly",[24,1639,1640],{},"The wrong comparison operator is used in conditions",[67,1642,1644],{"id":1643},"ways-to-extend-the-project","Ways to extend the project",[14,1646,1647],{},"Once the basic version works, try improving it.",[14,1649,1650],{},"You can:",[21,1652,1653,1656,1662,1665,1668],{},[24,1654,1655],{},"Add more fixed questions and answers",[24,1657,1658,1659,1661],{},"Add a ",[31,1660,1059],{}," command that lists available inputs",[24,1663,1664],{},"Store replies in a dictionary as a next-step refactor",[24,1666,1667],{},"Count how many messages the user sends",[24,1669,1670],{},"Save a chat log to a file",[14,1672,1673],{},"Here is one small extension idea: count messages.",[156,1675,1677],{"className":158,"code":1676,"language":160,"meta":161,"style":161},"print(\"Simple Chatbot\")\nprint(\"Type 'bye' to stop.\")\n\ncount = 0\n\nwhile True:\n    message = input(\"You: \").lower().strip()\n    count += 1\n\n    if message == \"hello\":\n        print(\"Bot: Hi!\")\n    elif message == \"bye\":\n        print(\"Bot: Goodbye!\")\n        print(\"Bot: You sent\", count, \"messages.\")\n        break\n    else:\n        print(\"Bot: Sorry, I don't understand.\")\n",[31,1678,1679,1693,1707,1711,1722,1726,1734,1760,1771,1775,1791,1805,1821,1835,1865,1869,1875],{"__ignoreMap":161},[165,1680,1681,1683,1685,1687,1689,1691],{"class":167,"line":168},[165,1682,172],{"class":171},[165,1684,176],{"class":175},[165,1686,180],{"class":179},[165,1688,184],{"class":183},[165,1690,180],{"class":179},[165,1692,189],{"class":175},[165,1694,1695,1697,1699,1701,1703,1705],{"class":167,"line":192},[165,1696,172],{"class":171},[165,1698,176],{"class":175},[165,1700,180],{"class":179},[165,1702,201],{"class":183},[165,1704,180],{"class":179},[165,1706,189],{"class":175},[165,1708,1709],{"class":167,"line":208},[165,1710,212],{"emptyLinePlaceholder":211},[165,1712,1713,1716,1718],{"class":167,"line":215},[165,1714,1715],{"class":231},"count ",[165,1717,236],{"class":235},[165,1719,1721],{"class":1720},"srdBf"," 0\n",[165,1723,1724],{"class":167,"line":228},[165,1725,212],{"emptyLinePlaceholder":211},[165,1727,1728,1730,1732],{"class":167,"line":267},[165,1729,128],{"class":218},[165,1731,222],{"class":221},[165,1733,225],{"class":175},[165,1735,1736,1738,1740,1742,1744,1746,1748,1750,1752,1754,1756,1758],{"class":167,"line":272},[165,1737,232],{"class":231},[165,1739,236],{"class":235},[165,1741,239],{"class":171},[165,1743,176],{"class":175},[165,1745,180],{"class":179},[165,1747,246],{"class":183},[165,1749,180],{"class":179},[165,1751,251],{"class":175},[165,1753,255],{"class":254},[165,1755,258],{"class":175},[165,1757,261],{"class":254},[165,1759,264],{"class":175},[165,1761,1762,1765,1768],{"class":167,"line":294},[165,1763,1764],{"class":231},"    count ",[165,1766,1767],{"class":235},"+=",[165,1769,1770],{"class":1720}," 1\n",[165,1772,1773],{"class":167,"line":311},[165,1774,212],{"emptyLinePlaceholder":211},[165,1776,1777,1779,1781,1783,1785,1787,1789],{"class":167,"line":330},[165,1778,275],{"class":218},[165,1780,278],{"class":231},[165,1782,281],{"class":235},[165,1784,284],{"class":179},[165,1786,287],{"class":183},[165,1788,180],{"class":179},[165,1790,225],{"class":175},[165,1792,1793,1795,1797,1799,1801,1803],{"class":167,"line":346},[165,1794,297],{"class":171},[165,1796,176],{"class":175},[165,1798,180],{"class":179},[165,1800,304],{"class":183},[165,1802,180],{"class":179},[165,1804,189],{"class":175},[165,1806,1807,1809,1811,1813,1815,1817,1819],{"class":167,"line":363},[165,1808,314],{"class":218},[165,1810,278],{"class":231},[165,1812,281],{"class":235},[165,1814,284],{"class":179},[165,1816,50],{"class":183},[165,1818,180],{"class":179},[165,1820,225],{"class":175},[165,1822,1823,1825,1827,1829,1831,1833],{"class":167,"line":379},[165,1824,297],{"class":171},[165,1826,176],{"class":175},[165,1828,180],{"class":179},[165,1830,372],{"class":183},[165,1832,180],{"class":179},[165,1834,189],{"class":175},[165,1836,1837,1839,1841,1843,1846,1848,1851,1854,1856,1858,1861,1863],{"class":167,"line":385},[165,1838,297],{"class":171},[165,1840,176],{"class":175},[165,1842,180],{"class":179},[165,1844,1845],{"class":183},"Bot: You sent",[165,1847,180],{"class":179},[165,1849,1850],{"class":175},",",[165,1852,1853],{"class":254}," count",[165,1855,1850],{"class":175},[165,1857,284],{"class":179},[165,1859,1860],{"class":183},"messages.",[165,1862,180],{"class":179},[165,1864,189],{"class":175},[165,1866,1867],{"class":167,"line":393},[165,1868,382],{"class":218},[165,1870,1871,1873],{"class":167,"line":1097},[165,1872,388],{"class":218},[165,1874,225],{"class":175},[165,1876,1877,1879,1881,1883,1885,1887],{"class":167,"line":1112},[165,1878,297],{"class":171},[165,1880,176],{"class":175},[165,1882,180],{"class":179},[165,1884,402],{"class":183},[165,1886,180],{"class":179},[165,1888,189],{"class":175},[14,1890,1891],{},"This adds one new idea without making the program too complex.",[67,1893,1895],{"id":1894},"when-to-move-to-the-next-topic","When to move to the next topic",[14,1897,1898],{},"You are ready for the next step when you understand:",[21,1900,1901,1907,1916,1922],{},[24,1902,1903,1904,1906],{},"how ",[31,1905,106],{}," gets text from the user",[24,1908,1903,1909,34,1911,38,1913,1915],{},[31,1910,33],{},[31,1912,37],{},[31,1914,41],{}," choose different actions",[24,1917,1918,1919,1921],{},"how a ",[31,1920,459],{}," loop repeats the chatbot",[24,1923,1903,1924,1926],{},[31,1925,136],{}," stops the loop",[14,1928,1929],{},"Good next topics are:",[21,1931,1932,1935,1938],{},[24,1933,1934],{},"functions to organize chatbot code better",[24,1936,1937],{},"dictionaries for cleaner reply matching",[24,1939,1940],{},"file handling if you want to save chat history",[14,1942,1943,1944,485],{},"A useful next lesson is ",[101,1945,1947],{"href":1946},"\u002Fhow-to\u002Fhow-to-create-a-simple-function-in-python\u002F","how to create a simple function in Python",[67,1949,1951],{"id":1950},"faq","FAQ",[408,1953,1955],{"id":1954},"is-this-a-real-ai-chatbot","Is this a real AI chatbot?",[14,1957,1958],{},"No. This example is a simple rule-based chatbot that matches user input to fixed replies.",[408,1960,1962,1963,143,1965,1967],{"id":1961},"why-use-lower-and-strip","Why use ",[31,1964,142],{},[31,1966,146],{},"?",[14,1969,1970],{},"They make input matching easier by removing extra spaces and converting text to lowercase.",[408,1972,1974],{"id":1973},"can-i-add-more-responses","Can I add more responses?",[14,1976,1977,1978,1980],{},"Yes. Add more ",[31,1979,37],{}," blocks or later move the replies into a dictionary.",[408,1982,1984],{"id":1983},"why-does-the-chatbot-keep-running","Why does the chatbot keep running?",[14,1986,1987,1988,1990,1991,1993],{},"It runs inside a ",[31,1989,459],{}," loop until the user enters the exit word and ",[31,1992,136],{}," stops the loop.",[408,1995,1997],{"id":1996},"what-python-topics-should-i-know-first","What Python topics should I know first?",[14,1999,2000,2001,2003,2004,2006],{},"Basic input, strings, ",[31,2002,33],{}," statements, and ",[31,2005,128],{}," loops are enough for this project.",[67,2008,2010],{"id":2009},"see-also","See also",[21,2012,2013,2021,2026,2030,2036,2041,2046],{},[24,2014,2015],{},[101,2016,2017,2018,2020],{"href":103},"Python ",[31,2019,106],{}," function explained",[24,2022,2023],{},[101,2024,2025],{"href":112},"Python if, else, and elif explained",[24,2027,2028],{},[101,2029,491],{"href":125},[24,2031,2032],{},[101,2033,2035],{"href":2034},"\u002Flearn\u002Fpython-strings-explained-basics-and-examples\u002F","Python strings explained: basics and examples",[24,2037,2038],{},[101,2039,2040],{"href":1946},"How to create a simple function in Python",[24,2042,2043],{},[101,2044,2045],{"href":1440},"SyntaxError: invalid syntax fix",[24,2047,2048],{},[101,2049,2051],{"href":2050},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block fix",[14,2053,2054],{},"Copy the chatbot, run it, and test a few messages.",[14,2056,2057],{},"Then improve it by:",[21,2059,2060,2063,2066],{},[24,2061,2062],{},"adding new replies",[24,2064,2065],{},"moving code into functions",[24,2067,2068],{},"saving chat history to a file",[14,2070,2071],{},"That is a great way to turn one small example into real Python practice.",[2073,2074,2075],"style",{},"html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":161,"searchDepth":192,"depth":192,"links":2077},[2078,2079,2080,2083,2084,2085,2086,2098,2099,2100,2108],{"id":69,"depth":192,"text":70},{"id":90,"depth":192,"text":91},{"id":150,"depth":192,"text":151,"children":2081},[2082],{"id":410,"depth":208,"text":411},{"id":789,"depth":192,"text":790},{"id":825,"depth":192,"text":826},{"id":875,"depth":192,"text":876},{"id":1180,"depth":192,"text":1181,"children":2087},[2088,2090,2092,2094,2096,2097],{"id":1187,"depth":208,"text":2089},"Forgetting parentheses after input",{"id":1258,"depth":208,"text":2091},"Using = instead of == in conditions",{"id":1354,"depth":208,"text":2093},"Forgetting the colon after if, elif, or else",{"id":1447,"depth":208,"text":2095},"Writing break outside the loop",{"id":1545,"depth":208,"text":1546},{"id":1603,"depth":208,"text":1604},{"id":1643,"depth":192,"text":1644},{"id":1894,"depth":192,"text":1895},{"id":1950,"depth":192,"text":1951,"children":2101},[2102,2103,2105,2106,2107],{"id":1954,"depth":208,"text":1955},{"id":1961,"depth":208,"text":2104},"Why use lower() and strip()?",{"id":1973,"depth":208,"text":1974},{"id":1983,"depth":208,"text":1984},{"id":1996,"depth":208,"text":1997},{"id":2009,"depth":192,"text":2010},"Master python simple chatbot example in our comprehensive Python beginner guide.","md",{},"\u002Fexamples\u002Fpython-simple-chatbot-example",{"title":5,"description":2109},"examples\u002Fpython-simple-chatbot-example","ccjQToAOJnGlGte8UQYi-A2YAiC-4w2y04v1fjofh7U",1777585477970]