From 7aa9753f84285634d32117175f70c5bf605d34b7 Mon Sep 17 00:00:00 2001 From: Souradeep Date: Thu, 19 Oct 2023 18:13:15 +0530 Subject: [PATCH 1/3] Added rock paper scissor game --- .../RockPaperScissor/gameRockPaperScissors.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Game/RockPaperScissor/gameRockPaperScissors.py diff --git a/Game/RockPaperScissor/gameRockPaperScissors.py b/Game/RockPaperScissor/gameRockPaperScissors.py new file mode 100644 index 00000000..2736fd61 --- /dev/null +++ b/Game/RockPaperScissor/gameRockPaperScissors.py @@ -0,0 +1,42 @@ +import random + +def get_user_choice(): + user_choice = input("Choose Rock, Paper, or Scissors: ").lower() + while user_choice not in ["rock", "paper", "scissors"]: + print("Invalid choice. Please choose Rock, Paper, or Scissors.") + user_choice = input("Choose Rock, Paper, or Scissors: ").lower() + return user_choice + +def get_computer_choice(): + return random.choice(["rock", "paper", "scissors"]) + +def determine_winner(user_choice, computer_choice): + if user_choice == computer_choice: + return "It's a tie!" + if ( + (user_choice == "rock" and computer_choice == "scissors") or + (user_choice == "paper" and computer_choice == "rock") or + (user_choice == "scissors" and computer_choice == "paper") + ): + return "You win!" + else: + return "Computer wins!" + +def main(): + print("Welcome to Rock, Paper, Scissors!") + while True: + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose {user_choice}") + print(f"Computer chose {computer_choice}") + + result = determine_winner(user_choice, computer_choice) + print(result) + + play_again = input("Do you want to play again? (yes/no): ").lower() + if play_again != "yes": + break + +if __name__ == "__main__": + main() From 5ae37ec09b9b80ce935c81c1375cec2bb88e37a3 Mon Sep 17 00:00:00 2001 From: SOURADEEP HAZRA <105676331+Souradeephazra123@users.noreply.github.com> Date: Tue, 24 Oct 2023 20:50:19 +0530 Subject: [PATCH 2/3] Create Level_order_traversal_in_a_binary_tree --- .../Level_order_traversal_in_a_binary_tree | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 DS&Algo Programs in Python/Level_order_traversal_in_a_binary_tree diff --git a/DS&Algo Programs in Python/Level_order_traversal_in_a_binary_tree b/DS&Algo Programs in Python/Level_order_traversal_in_a_binary_tree new file mode 100644 index 00000000..85d6f89e --- /dev/null +++ b/DS&Algo Programs in Python/Level_order_traversal_in_a_binary_tree @@ -0,0 +1,46 @@ +class TreeNode: + def __init__(self, key): + self.left = None + self.right = None + self.val = key + +def level_order_traversal(root): + if root is None: + return + + # Create an empty queue for level order traversal + queue = [] + + # Enqueue the root node + queue.append(root) + + while queue: + # Dequeue a node from the queue + node = queue.pop(0) + + # Print the node's value + print(node.val, end=' ') + + # Enqueue the left child + if node.left is not None: + queue.append(node.left) + + # Enqueue the right child + if node.right is not None: + queue.append(node.right) + +# Sample binary tree: +# 1 +# / \ +# 2 3 +# / \ +# 4 5 + +root = TreeNode(1) +root.left = TreeNode(2) +root.right = TreeNode(3) +root.left.left = TreeNode(4) +root.left.right = TreeNode(5) + +print("Level Order Traversal:") +level_order_traversal(root) From 3270bcf29cb52108d5ea734b2bfe796304a94b99 Mon Sep 17 00:00:00 2001 From: SOURADEEP HAZRA <105676331+Souradeephazra123@users.noreply.github.com> Date: Sat, 28 Oct 2023 02:55:28 +0530 Subject: [PATCH 3/3] Create gameRockPapterScissors.py --- .../gameRockPapterScissors.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Game/RockPaperScissor/gameRockPapterScissors.py diff --git a/Game/RockPaperScissor/gameRockPapterScissors.py b/Game/RockPaperScissor/gameRockPapterScissors.py new file mode 100644 index 00000000..2736fd61 --- /dev/null +++ b/Game/RockPaperScissor/gameRockPapterScissors.py @@ -0,0 +1,42 @@ +import random + +def get_user_choice(): + user_choice = input("Choose Rock, Paper, or Scissors: ").lower() + while user_choice not in ["rock", "paper", "scissors"]: + print("Invalid choice. Please choose Rock, Paper, or Scissors.") + user_choice = input("Choose Rock, Paper, or Scissors: ").lower() + return user_choice + +def get_computer_choice(): + return random.choice(["rock", "paper", "scissors"]) + +def determine_winner(user_choice, computer_choice): + if user_choice == computer_choice: + return "It's a tie!" + if ( + (user_choice == "rock" and computer_choice == "scissors") or + (user_choice == "paper" and computer_choice == "rock") or + (user_choice == "scissors" and computer_choice == "paper") + ): + return "You win!" + else: + return "Computer wins!" + +def main(): + print("Welcome to Rock, Paper, Scissors!") + while True: + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose {user_choice}") + print(f"Computer chose {computer_choice}") + + result = determine_winner(user_choice, computer_choice) + print(result) + + play_again = input("Do you want to play again? (yes/no): ").lower() + if play_again != "yes": + break + +if __name__ == "__main__": + main()