├── chatbotwithpython.py └── guessinggame.py /chatbotwithpython.py: -------------------------------------------------------------------------------- 1 | 2 | dataset = { 3 | "greeting": { 4 | "keywords": ["hello", "hi", "greetings", "hey"], 5 | "responses": ["Hello! How can I assist you today?", 6 | "Hi there! Need help with something?"] 7 | }, 8 | "pricing": { 9 | "keywords": ["price", "cost", "pricing", "charge"], 10 | "responses": ["Our pricing depends on your requirements. Would you like to discuss details?", 11 | "You can check our pricing plans on our website. Do you need a link?"] 12 | }, 13 | "technical_issue": { 14 | "keywords": ["issue", "problem", "bug", "error"], 15 | "responses": ["I'm sorry to hear about the issue. Can you describe the problem?", 16 | "Let me assist you with the issue. Please provide more details."] 17 | }, 18 | "services": { 19 | "keywords": ["service", "offer", "solutions", "product"], 20 | "responses": ["We offer software development, system integration, and maintenance services.", 21 | "Our services include web development, mobile apps, and cloud solutions. What are you looking for?"] 22 | }, 23 | "goodbye": { 24 | "keywords": ["bye", "goodbye", "see you", "exit"], 25 | "responses": ["Goodbye! Feel free to reach out anytime.", 26 | "Take care! We’re here if you need us."] 27 | }, 28 | "unknown": { 29 | "responses": ["I'm sorry, I didn't understand that. Could you please rephrase?", 30 | "Can you provide more details? I'm here to help."] 31 | } 32 | } 33 | 34 | # NLU function to identify user intent based on keywords 35 | def identify_intent(user_input): 36 | for intent, data in dataset.items(): 37 | if intent != "unknown": 38 | for keyword in data["keywords"]: 39 | if keyword.lower() in user_input.lower(): 40 | return intent 41 | return "unknown" 42 | 43 | # Function to generate response 44 | import random 45 | 46 | def generate_response(intent): 47 | return random.choice(dataset[intent]["responses"]) 48 | 49 | # Chatbot function 50 | def chatbot(): 51 | print("Chatbot: Hello! Welcome to our software firm. How can I help you today?") 52 | while True: 53 | user_input = input("You: ").strip() 54 | if user_input.lower() in ["exit", "quit"]: 55 | print("Chatbot: Goodbye! Have a great day!") 56 | break 57 | # Identify intent 58 | intent = identify_intent(user_input) 59 | # Generate response 60 | response = generate_response(intent) 61 | print(f"Chatbot: {response}") 62 | 63 | # Run the chatbot 64 | if __name__ == "__main__": 65 | chatbot() 66 | 67 | -------------------------------------------------------------------------------- /guessinggame.py: -------------------------------------------------------------------------------- 1 | import random 2 | jackpot = random.randint(1,100) 3 | 4 | guess = int(input("Guess an int num:")) 5 | 6 | counter=1 7 | 8 | while guess != jackpot: 9 | if guess>jackpot: 10 | print("Guess a lower num.") 11 | 12 | else: 13 | print("Guess a higher num.") 14 | 15 | guess = int(input("Guess an int num:")) 16 | counter+=1 17 | 18 | print("Predicted num is correct.") 19 | print("You took",counter,"attempts.") 20 | --------------------------------------------------------------------------------