Files
ui-cviko1/notebook/cviko1_2-chatbot.ipynb
2025-02-19 22:11:03 +01:00

98 lines
2.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"< My name is AI-CHATBOT.\n",
"< I can't do that.\n",
"< Nope.\n",
"< The sky is blue.\n",
"< Bye\n"
]
}
],
"source": [
"import random\n",
"\n",
"no_responses = [\n",
" \"I can't answer that.\",\n",
" \"I don't know, sorry.\",\n",
" \"I can't understand you.\",\n",
" \"Can you elaborate, please?\"\n",
"]\n",
"\n",
"responses = {\n",
" \"What's the weather like today?\": [\n",
" \"It's sunny!\",\n",
" \"It seems sunny today.\",\n",
" \"Sunny.\"\n",
" ],\n",
" \"What is your name?\": [\n",
" \"My name is AI-CHATBOT.\",\n",
" \"It's AI-CHATBOT.\",\n",
" ],\n",
" \"What's your favorite color?\": [\n",
" \"It's yellow.\",\n",
" \"Yellow.\"\n",
" ],\n",
" \"What color is the sky?\": [\n",
" \"The sky is blue.\",\n",
" \"It's blue.\"\n",
" ],\n",
" \"Can you talk?\": [\n",
" \"No.\",\n",
" \"Nope.\",\n",
" \"I can't do that.\"\n",
" ]\n",
"}\n",
"\n",
"while True:\n",
" message = input(\"> \")\n",
"\n",
" if message == \"bye\":\n",
" print(\"< Bye\")\n",
" break\n",
" \n",
" if message in responses.keys():\n",
" print(\"<\", random.choice(responses[message]))\n",
" else:\n",
" print(\"<\", random.choice(no_responses))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ui-cviko1",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}