Python Data Science Jobs & Interviews
20.4K subscribers
188 photos
4 videos
25 files
326 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
Q: How can you simulate basic human-like behavior in a simple program using Python?

Imagine a chatbot that responds to user inputs with random, yet plausible, replies—mimicking how people react in conversations. For beginners, this involves using random module to generate responses based on keywords. Here’s a simple example:

import random

responses = {
"hello": ["Hi there!", "Hello!", "Hey!"],
"how are you": ["I'm good, thanks!", "Doing well!", "Pretty great!"],
"bye": ["Goodbye!", "See you later!", "Bye!"]
}

def chatbot():
while True:
user_input = input("You: ").lower()
if user_input == "quit":
print("Bot: Goodbye!")
break
for key in responses:
if key in user_input:
print(f"Bot: {random.choice(responses[key])}")
break
else:
print("Bot: I don't understand. Can you rephrase?")

chatbot()

This simulates basic human-like interaction by matching keywords and responding randomly from predefined lists. It’s a foundational step toward more advanced behavioral simulation.

#Python #BeginnerProgramming #Chatbot #HumanBehaviorSimulation #CodeExample

By: @DataScienceQ 🚀