├── README.md ├── chatbot.py ├── chatbot1.py └── tic tac toe with AI.py /README.md: -------------------------------------------------------------------------------- 1 | Hello Guys,This is SIVADHARSHINI,Currently pursuing B.Tech Artificial Intelligence and Machine Learning. As a passionate learner, I focusing on enhancing my skills in Python with Machine Learning.I am eager to contribute my creativity skills to build efficient and user-friendly Data manipulations and other AI based applications.Connect with me to collaborate on exciting projects!!! 2 | . 3 | -------------------------------------------------------------------------------- /chatbot.py: -------------------------------------------------------------------------------- 1 | def chatbot_response(user_input): 2 | if "hi" in user_input.lower() or "hello" in user_input.lower(): 3 | return "Hello! How can I help you today?" 4 | elif "how are you" in user_input.lower(): 5 | return "I'm just a chatbot, so I don't have feelings, but thanks for asking!" 6 | elif "goodbye" in user_input.lower() or "bye" in user_input.lower(): 7 | return "Goodbye! Have a great day!" 8 | else: 9 | return "I'm sorry, I didn't understand that. Can you please rephrase your question?" 10 | 11 | # Main loop for chatting with the user 12 | while True: 13 | user_input = input("User: ") 14 | response = chatbot_response(user_input) 15 | print("Chatbot:", response) 16 | -------------------------------------------------------------------------------- /chatbot1.py: -------------------------------------------------------------------------------- 1 | def chatbot(): 2 | print("Hello! I'm a simple chatbot. How can I help you today?") 3 | 4 | while True: 5 | user_input = input("You: ").lower() 6 | 7 | if "hello" in user_input or "hi" in user_input: 8 | print("Chatbot: Hello! How can I assist you?") 9 | elif "how are you" in user_input: 10 | print("Chatbot: I'm just a computer program, but thanks for asking!") 11 | elif "bye" in user_input: 12 | print("Chatbot: Goodbye! Have a great day.") 13 | break 14 | else: 15 | print("Chatbot: I'm sorry, I don't understand. Can you please rephrase your question?") 16 | 17 | chatbot() 18 | -------------------------------------------------------------------------------- /tic tac toe with AI.py: -------------------------------------------------------------------------------- 1 | import copy 2 | 3 | def print_board(board): 4 | for row in board: 5 | print(" | ".join(row)) 6 | print("-" * 5) 7 | 8 | def check_winner(board, player): 9 | for i in range(3): 10 | if all([cell == player for cell in board[i]]): 11 | return True 12 | if all([board[j][i] == player for j in range(3)]): 13 | return True 14 | if all([board[i][i] == player for i in range(3)]) or all([board[i][2-i] == player for i in range(3)]): 15 | return True 16 | return False 17 | 18 | def is_full(board): 19 | return all([cell != ' ' for row in board for cell in row]) 20 | 21 | def get_empty_cells(board): 22 | return [(i, j) for i in range(3) for j in range(3) if board[i][j] == ' '] 23 | 24 | def minmax(board, depth, maximizing_player): 25 | if check_winner(board, 'X'): 26 | return -1 27 | if check_winner(board, 'O'): 28 | return 1 29 | if is_full(board): 30 | return 0 31 | 32 | if maximizing_player: 33 | max_eval = float("-inf") 34 | for i, j in get_empty_cells(board): 35 | new_board = copy.deepcopy(board) 36 | new_board[i][j] = 'O' 37 | eval = minmax(new_board, depth+1, False) 38 | max_eval = max(max_eval, eval) 39 | return max_eval 40 | else: 41 | min_eval = float("inf") 42 | for i, j in get_empty_cells(board): 43 | new_board = copy.deepcopy(board) 44 | new_board[i][j] = 'X' 45 | eval = minmax(new_board, depth+1, True) 46 | min_eval = min(min_eval, eval) 47 | return min_eval 48 | 49 | def ai_move(board): 50 | best_move = None 51 | best_eval = float("-inf") 52 | for i, j in get_empty_cells(board): 53 | new_board = copy.deepcopy(board) 54 | new_board[i][j] = 'O' 55 | eval = minmax(new_board, 0, False) 56 | if eval > best_eval: 57 | best_eval = eval 58 | best_move = (i, j) 59 | return best_move 60 | 61 | def main(): 62 | board = [[' ' for _ in range(3)] for _ in range(3)] 63 | print_board(board) 64 | 65 | while True: 66 | human_move = input("Enter your move (row col): ") 67 | i, j = map(int, human_move.split()) 68 | board[i][j] = 'X' 69 | print_board(board) 70 | 71 | if check_winner(board, 'X'): 72 | print("You win!") 73 | break 74 | if is_full(board): 75 | print("It's a tie!") 76 | break 77 | 78 | ai_move_i, ai_move_j = ai_move(board) 79 | board[ai_move_i][ai_move_j] = 'O' 80 | print(f"AI placed O at: {ai_move_i} {ai_move_j}") 81 | print_board(board) 82 | 83 | if check_winner(board, 'O'): 84 | print("AI wins!") 85 | break 86 | if is_full(board): 87 | print("It's a tie!") 88 | break 89 | 90 | if __name__ == "__main__": 91 | main() 92 | --------------------------------------------------------------------------------