In this step-by-step tutorial, youโll learn how to create a simple yet powerful chatbot using Python โ all on your Android phone using the PyDroid 3 app. This chatbot will not only respond to your questions but also learn from you and remember responses. Perfect for beginners in coding and mobile development!
PyDroid 3 allows you to run Python code directly on your Android device. Itโs beginner-friendly, works offline, and is great for learning Python without needing a computer. Youโll write and run Python files just like you would on a PC.
import json # Load previous data or start fresh try: with open("bot_data.json") as f: data = json.load(f) except: data = {} print("Bot: Hi! Ask me anything.") while True: msg = input("You: ").lower() if msg in data: print("Bot:", data[msg]) else: print("Bot: I don't know that. Teach me!") reply = input("Your reply: ") data[msg] = reply with open("bot_data.json", "w") as f: json.dump(data, f) print("Bot: Thanks for correcting me! Whatโs your next question?")
json.load()
loads saved chatbot datainput()
gets user messagesjson.dump()
saves the new info so the bot remembers next timeThis chatbot is just the beginning of what you can build with Python on your phone. As you learn more, you can expand it with advanced features. If you enjoyed this tutorial, check out more projects and subscribe to my YouTube channel!
โโโโโ What feature should we add next? Drop your ideas in the comment section below!