From bc91db4996af47b1eab0e7873499980568dd84f2 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:27:50 +0200 Subject: [PATCH 01/20] Updated console output to enhance user experience The console output was updated to gereralise the user experience and make the output more personal. --- Rock Paper Scissor/rps.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Rock Paper Scissor/rps.py b/Rock Paper Scissor/rps.py index 90f3fd39..30f74fb4 100644 --- a/Rock Paper Scissor/rps.py +++ b/Rock Paper Scissor/rps.py @@ -2,16 +2,17 @@ # Print multiline instruction # performstring concatenation of string -print("Winning Rules of the Rock paper scissor game as follows: \n" - +"Rock vs paper->paper wins \n" - + "Rock vs scissor->Rock wins \n" - +"paper vs scissor->scissor wins \n") +print("Winning Rules of the Rock Paper Scissor game as follows: \n" + +"Rock vs Paper->Paper wins \n" + + "Rock vs Scissor->Rock wins \n" + +"Paper vs Scissor->Scissor wins \n" + +"Similar selcetions result in a draw. \n") while True: - print("Enter choice by entering the appropiate number \n 1. Rock \n 2. paper \n 3. scissor \n") + print("Enter choice by entering the appropiate number \n 1. Rock \n 2. Paper \n 3. Scissor \n") # take the input from user - choice = int(input("User turn: ")) + choice = int(input("It is your turn, please choose: ")) # OR is the short-circuit operator # if any one of the condition is true @@ -19,7 +20,7 @@ # looping until user enter invalid input while choice > 3 or choice < 1: - choice = int(input("enter valid input: ")) + choice = int(input("Please enter a number between 1 and 3: ")) # initialize value of choice_name variable @@ -27,13 +28,13 @@ if choice == 1: choice_name = 'Rock' elif choice == 2: - choice_name = 'paper' + choice_name = 'Paper' else: - choice_name = 'scissor' + choice_name = 'Scissor' # print user choice - print("user choice is: " + choice_name) - print("\nNow its computer turn.......") + print("You chosed: " + choice_name) + print("\nNow its my turn.......") # Computer chooses randomly any number # among 1 , 2 and 3. Using randint method @@ -50,27 +51,27 @@ if comp_choice == 1: comp_choice_name = 'Rock' elif comp_choice == 2: - comp_choice_name = 'paper' + comp_choice_name = 'Paper' else: - comp_choice_name = 'scissor' + comp_choice_name = 'Scissor' - print("Computer choice is: " + comp_choice_name) + print("I did choose: " + comp_choice_name) print(choice_name + " V/s " + comp_choice_name) # condition for winning if((choice == 1 and comp_choice == 2) or (choice == 2 and comp_choice ==1 )): - print("paper wins => ", end = "") - result = "paper" + print("Paper wins => ", end = "") + result = "Paper" elif((choice == 1 and comp_choice == 3) or (choice == 3 and comp_choice == 1)): print("Rock wins =>", end = "") result = "Rock" else: - print("scissor wins =>", end = "") - result = "scissor" + print("Scissor wins =>", end = "") + result = "Scissor" # Printing either user or computer wins if result == choice_name: From 3ad8293b0b314dfc0724b03d772dcef31e48cf15 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 23 Jun 2024 21:42:29 +0200 Subject: [PATCH 02/20] Update rps.py Added logic for draw --- Rock Paper Scissor/rps.py | 65 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/Rock Paper Scissor/rps.py b/Rock Paper Scissor/rps.py index 30f74fb4..f211c91d 100644 --- a/Rock Paper Scissor/rps.py +++ b/Rock Paper Scissor/rps.py @@ -40,44 +40,43 @@ # among 1 , 2 and 3. Using randint method # of random module comp_choice = random.randint(1, 3) - - # looping until comp_choice value - # is equal to the choice value - while comp_choice == choice: - comp_choice = random.randint(1, 3) - - # initialize value of comp_choice_name - # variable corresponding to the choice value - if comp_choice == 1: - comp_choice_name = 'Rock' - elif comp_choice == 2: - comp_choice_name = 'Paper' - else: - comp_choice_name = 'Scissor' + #check for draw + if comp_choice == choice: + print("We both choose "+choice_name) + print(" - It´s a draw") + else: + # initialize value of comp_choice_name + # variable corresponding to the choice value + if comp_choice == 1: + comp_choice_name = 'Rock' + elif comp_choice == 2: + comp_choice_name = 'Paper' + else: + comp_choice_name = 'Scissor' - print("I did choose: " + comp_choice_name) + print("I did choose: " + comp_choice_name) - print(choice_name + " V/s " + comp_choice_name) + print(choice_name + " V/s " + comp_choice_name) - # condition for winning - if((choice == 1 and comp_choice == 2) or - (choice == 2 and comp_choice ==1 )): - print("Paper wins => ", end = "") - result = "Paper" + # condition for winning + if((choice == 1 and comp_choice == 2) or + (choice == 2 and comp_choice ==1 )): + print("Paper wins => ", end = "") + result = "Paper" - elif((choice == 1 and comp_choice == 3) or - (choice == 3 and comp_choice == 1)): - print("Rock wins =>", end = "") - result = "Rock" - else: - print("Scissor wins =>", end = "") - result = "Scissor" + elif((choice == 1 and comp_choice == 3) or + (choice == 3 and comp_choice == 1)): + print("Rock wins =>", end = "") + result = "Rock" + else: + print("Scissor wins =>", end = "") + result = "Scissor" - # Printing either user or computer wins - if result == choice_name: - print("<== User wins ==>") - else: - print("<== Computer wins ==>") + # Printing either user or computer wins + if result == choice_name: + print("<== User wins ==>") + else: + print("<== Computer wins ==>") print("Do you want to play again? (Y/N)") ans = input() From 3437b38dc1adb2c7448e7bb84eb89ad7b2c9f6a8 Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:12:17 +0200 Subject: [PATCH 03/20] Create Rock Paper Scissors - New Version --- Rock Paper Scissors - New Version | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Rock Paper Scissors - New Version diff --git a/Rock Paper Scissors - New Version b/Rock Paper Scissors - New Version new file mode 100644 index 00000000..b7b3f030 --- /dev/null +++ b/Rock Paper Scissors - New Version @@ -0,0 +1,50 @@ +import random + +def get_user_choice(): + choices = ["rock", "paper", "scissors", "lizard", "spock"] + user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower() + while user_choice not in choices: + user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower() + return user_choice + +def get_computer_choice(): + choices = ["rock", "paper", "scissors", "lizard", "spock"] + return random.choice(choices) + +def determine_winner(user_choice, computer_choice): + win_conditions = { + "scissors": ["paper", "lizard"], + "paper": ["rock", "spock"], + "rock": ["lizard", "scissors"], + "lizard": ["spock", "paper"], + "spock": ["scissors", "rock"] + } + + if user_choice == computer_choice: + return "tie" + elif computer_choice in win_conditions[user_choice]: + return "user" + else: + return "computer" + +def play_game(): + print("Welcome to Rock, Paper, Scissors, Lizard, Spock!") + + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose: {user_choice}") + print(f"Computer chose: {computer_choice}") + + winner = determine_winner(user_choice, computer_choice) + + if winner == "tie": + print("It's a tie! Let's play again.") + play_game() + elif winner == "user": + print("You win!") + else: + print("Computer wins!") + +if __name__ == "__main__": + play_game() From e8c69a258eee968e499fe25654731a662888e84f Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:36:54 +0200 Subject: [PATCH 04/20] Add files via upload --- Rock Paper Scissors -New/rps.py | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Rock Paper Scissors -New/rps.py diff --git a/Rock Paper Scissors -New/rps.py b/Rock Paper Scissors -New/rps.py new file mode 100644 index 00000000..85822360 --- /dev/null +++ b/Rock Paper Scissors -New/rps.py @@ -0,0 +1,52 @@ +import random + +def get_user_choice(): + choices = ["rock", "paper", "scissors", "lizard", "spock"] + user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower() + while user_choice not in choices: + user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower() + return user_choice + +def get_computer_choice(): + choices = ["rock", "paper", "scissors", "lizard", "spock"] + return random.choice(choices) + +def determine_winner(user_choice, computer_choice): + win_conditions = { + "scissors": ["paper", "lizard"], + "paper": ["rock", "spock"], + "rock": ["lizard", "scissors"], + "lizard": ["spock", "paper"], + "spock": ["scissors", "rock"] + } + + if user_choice == computer_choice: + return "tie" + elif computer_choice in win_conditions[user_choice]: + return "user" + else: + return "computer" + +def play_game(): + print("Welcome to Rock, Paper, Scissors, Lizard, Spock!") + + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose: {user_choice}") + print(f"Computer chose: {computer_choice}") + + winner = determine_winner(user_choice, computer_choice) + + if winner == "tie": + print("It's a tie! Let's play again.") + play_game() + elif winner == "user": + print("You win!") + else: + print("Computer wins!") + +if __name__ == "__main__": + play_game() + + From 7da4be352a1928d8bf4b66f3ce87a61ba2f8f133 Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:40:14 +0200 Subject: [PATCH 05/20] Create README.txt --- Rock Paper Scissors -New/README.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Rock Paper Scissors -New/README.txt diff --git a/Rock Paper Scissors -New/README.txt b/Rock Paper Scissors -New/README.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Rock Paper Scissors -New/README.txt @@ -0,0 +1 @@ + From 7820e51e0ae156690865ef94f26c5ac711bf26eb Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:44:10 +0200 Subject: [PATCH 06/20] Delete Rock Paper Scissors -New/README.md --- Rock Paper Scissors -New/README.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Rock Paper Scissors -New/README.txt diff --git a/Rock Paper Scissors -New/README.txt b/Rock Paper Scissors -New/README.txt deleted file mode 100644 index 8b137891..00000000 --- a/Rock Paper Scissors -New/README.txt +++ /dev/null @@ -1 +0,0 @@ - From 40fb4a3c473feab9117455babe1c9bba9b40816c Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:45:37 +0200 Subject: [PATCH 07/20] Create README.md --- Rock Paper Scissors -New/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Rock Paper Scissors -New/README.md diff --git a/Rock Paper Scissors -New/README.md b/Rock Paper Scissors -New/README.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Rock Paper Scissors -New/README.md @@ -0,0 +1 @@ + From 2e8ca0a4a3d3f17b38551f32c752431776c087b9 Mon Sep 17 00:00:00 2001 From: Nico Ivander Setiady <77823185+NicoIvander@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:07:16 +0200 Subject: [PATCH 08/20] Score Tracking I add a feature so the player could choose whether they still want to play the game or not. If the player choose to end the game, the coding will show the final score between the player and the computer --- Rock Paper Scissors -New/rps.py | 46 +++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Rock Paper Scissors -New/rps.py b/Rock Paper Scissors -New/rps.py index 85822360..f13a3c08 100644 --- a/Rock Paper Scissors -New/rps.py +++ b/Rock Paper Scissors -New/rps.py @@ -28,25 +28,39 @@ def determine_winner(user_choice, computer_choice): return "computer" def play_game(): - print("Welcome to Rock, Paper, Scissors, Lizard, Spock!") - - user_choice = get_user_choice() - computer_choice = get_computer_choice() + user_score = 0 + computer_score = 0 - print(f"You chose: {user_choice}") - print(f"Computer chose: {computer_choice}") + print("Welcome to Rock, Paper, Scissors, Lizard, Spock!") - winner = determine_winner(user_choice, computer_choice) + while True: + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose: {user_choice}") + print(f"Computer chose: {computer_choice}") + + winner = determine_winner(user_choice, computer_choice) + + if winner == "tie": + print("It's a tie!") + elif winner == "user": + print("You win this round!") + user_score += 1 + else: + print("Computer wins this round!") + computer_score += 1 + + print(f"Score -> You: {user_score}, Computer: {computer_score}") + + play_again = input("Do you want to play again? (yes/no): ").lower() + if play_again != "yes": + break - if winner == "tie": - print("It's a tie! Let's play again.") - play_game() - elif winner == "user": - print("You win!") - else: - print("Computer wins!") + print("Final Score") + print(f"You: {user_score}") + print(f"Computer: {computer_score + 1}") + print("Thanks for playing!") if __name__ == "__main__": play_game() - - From c2d142c006ac468863fe0af2f64208d9b0ceac1e Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:20:28 +0200 Subject: [PATCH 09/20] Rock, Paper, Scissors, Lizard, Spock: Customizable Rounds I add a feature so the player could decide how many rounds for each game --- Rock Paper Scissors -New/rps.py | 83 +++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/Rock Paper Scissors -New/rps.py b/Rock Paper Scissors -New/rps.py index f13a3c08..6a172ac9 100644 --- a/Rock Paper Scissors -New/rps.py +++ b/Rock Paper Scissors -New/rps.py @@ -1,5 +1,6 @@ import random + def get_user_choice(): choices = ["rock", "paper", "scissors", "lizard", "spock"] user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower() @@ -7,10 +8,12 @@ def get_user_choice(): user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower() return user_choice + def get_computer_choice(): choices = ["rock", "paper", "scissors", "lizard", "spock"] return random.choice(choices) + def determine_winner(user_choice, computer_choice): win_conditions = { "scissors": ["paper", "lizard"], @@ -19,7 +22,7 @@ def determine_winner(user_choice, computer_choice): "lizard": ["spock", "paper"], "spock": ["scissors", "rock"] } - + if user_choice == computer_choice: return "tie" elif computer_choice in win_conditions[user_choice]: @@ -27,40 +30,58 @@ def determine_winner(user_choice, computer_choice): else: return "computer" + def play_game(): - user_score = 0 - computer_score = 0 - print("Welcome to Rock, Paper, Scissors, Lizard, Spock!") - + while True: - user_choice = get_user_choice() - computer_choice = get_computer_choice() - - print(f"You chose: {user_choice}") - print(f"Computer chose: {computer_choice}") - - winner = determine_winner(user_choice, computer_choice) - - if winner == "tie": - print("It's a tie!") - elif winner == "user": - print("You win this round!") - user_score += 1 - else: - print("Computer wins this round!") - computer_score += 1 - - print(f"Score -> You: {user_score}, Computer: {computer_score}") - - play_again = input("Do you want to play again? (yes/no): ").lower() - if play_again != "yes": + while True: + try: + num_rounds = int(input("Enter the number of rounds you want to play: ")) + if num_rounds <= 0: + print("Please enter a positive number.") + continue + break + except ValueError: + print("Invalid input. Please enter a number.") + + user_score = 0 + computer_score = 0 + ties = 0 + + for round_number in range(1, num_rounds + 1): + print(f"\nRound {round_number}/{num_rounds}") + + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"\nYou chose: {user_choice}") + print(f"Computer chose: {computer_choice}") + + winner = determine_winner(user_choice, computer_choice) + + if winner == "tie": + print("It's a tie!") + ties += 1 + elif winner == "user": + print("You win!") + user_score += 1 + else: + print("Computer wins!") + computer_score += 1 + + print(f"\nScores:\nUser: {user_score}\nComputer: {computer_score}\nTies: {ties}") + + print("\nFinal Scores:") + print(f"User: {user_score}") + print(f"Computer: {computer_score}") + print(f"Ties: {ties}") + + play_again = input("\nDo you want to play again? (y/n): ").lower() + if play_again != "y": + print("Thanks for playing!") break - - print("Final Score") - print(f"You: {user_score}") - print(f"Computer: {computer_score + 1}") - print("Thanks for playing!") + if __name__ == "__main__": play_game() From f58f567c5195f8d1f6851698529e413ccc7abcac Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:54:14 +0200 Subject: [PATCH 10/20] Update README.md --- Rock Paper Scissors -New/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Rock Paper Scissors -New/README.md b/Rock Paper Scissors -New/README.md index 8b137891..7dce0873 100644 --- a/Rock Paper Scissors -New/README.md +++ b/Rock Paper Scissors -New/README.md @@ -1 +1,30 @@ +# Rock, Paper, Scissors, Lizard, Spock Game + +This is a Python implementation of the classic Rock, Paper, Scissors game extended with two additional options: Lizard and Spock. + +## Rules + +- **Scissors** cuts **Paper** +- **Paper** covers **Rock** +- **Rock** crushes **Lizard** +- **Lizard** poisons **Spock** +- **Spock** smashes **Scissors** +- **Scissors** decapitates **Lizard** +- **Lizard** eats **Paper** +- **Paper** disproves **Spock** +- **Spock** vaporizes **Rock** +- **Rock** crushes **Scissors** + +## How to Play + +1. **Setup:** Run the Python script `rps.py`. +2. **Gameplay:** + - Enter the number of rounds you want to play. + - For each round, enter your choice: rock, paper, scissors, lizard, or spock. + - The computer will randomly select its choice. + - The winner of each round is determined based on the rules above. + - Scores (user wins, computer wins, and ties) are displayed after each round. +3. **End of Game:** + - After completing all rounds, final scores are displayed. + - You have the option to play again or exit. From e3736f1c92e66273a5f24db79ef9fdfdcf457bb8 Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 17:12:49 +0200 Subject: [PATCH 11/20] Update README.md Adding the Table of Content for Rock Paper Scissors -New --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0aa9b5be..729cb420 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,8 @@ More information on contributing and the general code of conduct for discussion | QR Code Generator | [QR Code Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/QR%20Code%20Generator) | This is generate a QR code from the provided link | | Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values! | | Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. | -| ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor) | A game of Rock Paper Scissors. | +| ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor) | A game of Rock Paper Scissors. +| Rock Paper Scissors -New | [Rock Paper Scissors -New] (https://github.com/bbob122/Python-Scripts/tree/new_features/Rock%20Paper%20Scissors%20-New) | Updated Rock Paper Scissors with new feature. | Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and emails you when it completes execution. | | Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie%20with%20Python) | Take your selfie with python . | | Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! | From 6cdda9ab6ab5a42f7d83ce1a88de7af8294e82a7 Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 17:14:53 +0200 Subject: [PATCH 12/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 729cb420..86e22dfd 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ More information on contributing and the general code of conduct for discussion | Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values! | | Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. | | ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor) | A game of Rock Paper Scissors. -| Rock Paper Scissors -New | [Rock Paper Scissors -New] (https://github.com/bbob122/Python-Scripts/tree/new_features/Rock%20Paper%20Scissors%20-New) | Updated Rock Paper Scissors with new feature. +| Rock Paper Scissors -New | [Rock Paper Scissors -New] (https://github.com/bbob122/Python-Scripts/tree/new_features/Rock%20Paper%20Scissors%20-New) | Updated Rock Paper Scissors with new feature. | | Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and emails you when it completes execution. | | Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie%20with%20Python) | Take your selfie with python . | | Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! | From 6adfd094ef476893d54cda7856d777b26259ada2 Mon Sep 17 00:00:00 2001 From: Aziz-Naidja <135458281+Aziz-Naidja@users.noreply.github.com> Date: Thu, 27 Jun 2024 17:17:37 +0200 Subject: [PATCH 13/20] Update README.md Fixing the link for the new File --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86e22dfd..fb935bf2 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ More information on contributing and the general code of conduct for discussion | Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values! | | Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. | | ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor) | A game of Rock Paper Scissors. -| Rock Paper Scissors -New | [Rock Paper Scissors -New] (https://github.com/bbob122/Python-Scripts/tree/new_features/Rock%20Paper%20Scissors%20-New) | Updated Rock Paper Scissors with new feature. | +| Rock Paper Scissors -New | [Rock Paper Scissors -New](https://github.com/bbob122/Python-Scripts/tree/new_features/Rock%20Paper%20Scissors%20-New) | Updated Rock Paper Scissors with new feature. | | Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and emails you when it completes execution. | | Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie%20with%20Python) | Take your selfie with python . | | Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! | From e967746350680aba9ad5b98a2d9fee0623c140ee Mon Sep 17 00:00:00 2001 From: Nico Ivander Setiady <77823185+NicoIvander@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:18:14 +0200 Subject: [PATCH 14/20] Initializing new project --- Pomodoro Timer/pomodoro.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Pomodoro Timer/pomodoro.py diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py new file mode 100644 index 00000000..daaa971e --- /dev/null +++ b/Pomodoro Timer/pomodoro.py @@ -0,0 +1,15 @@ +import time + +def countdown(minutes): + seconds = minutes * 60 + while seconds: + mins, secs = divmod(seconds, 60) + timer = f'{mins:02d}:{secs:02d}' + print(timer, end='\r') + time.sleep(1) + seconds -= 1 + print('Time is up!') + +# Example usage: +countdown(1) # for a 25-minute work session +countdown(1) # for a 5-minute break From 6589c3a22f73bb46712370bc70bdc1b9c7dc5c94 Mon Sep 17 00:00:00 2001 From: Niloofar Date: Sat, 29 Jun 2024 21:56:53 +0200 Subject: [PATCH 15/20] improve play again confirmation logic --- Python-Scripts | 1 + Rock Paper Scissors -New/rps.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 160000 Python-Scripts diff --git a/Python-Scripts b/Python-Scripts new file mode 160000 index 00000000..3ad8293b --- /dev/null +++ b/Python-Scripts @@ -0,0 +1 @@ +Subproject commit 3ad8293b0b314dfc0724b03d772dcef31e48cf15 diff --git a/Rock Paper Scissors -New/rps.py b/Rock Paper Scissors -New/rps.py index 6a172ac9..1a488b17 100644 --- a/Rock Paper Scissors -New/rps.py +++ b/Rock Paper Scissors -New/rps.py @@ -1,8 +1,8 @@ import random +choices = ["rock", "paper", "scissors", "lizard", "spock"] def get_user_choice(): - choices = ["rock", "paper", "scissors", "lizard", "spock"] user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower() while user_choice not in choices: user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower() @@ -10,7 +10,6 @@ def get_user_choice(): def get_computer_choice(): - choices = ["rock", "paper", "scissors", "lizard", "spock"] return random.choice(choices) @@ -76,12 +75,16 @@ def play_game(): print(f"User: {user_score}") print(f"Computer: {computer_score}") print(f"Ties: {ties}") + + while True: + play_again = input("\nDo you want to play again? (y/n): ").lower() + if play_again in ["y", "n"]: + break + print("Invalid input. Please enter 'y' or 'n'.") - play_again = input("\nDo you want to play again? (y/n): ").lower() if play_again != "y": print("Thanks for playing!") break - if __name__ == "__main__": play_game() From d95981e2d521b273e630c525313265a38fea69f6 Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:52:28 +0200 Subject: [PATCH 16/20] Update pomodoro.py new ui --- Pomodoro Timer/pomodoro.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index daaa971e..e6e99cef 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -1,15 +1,23 @@ import time +from tqdm import tqdm +from colorama import init, Fore, Style + +# Initialize colorama +init(autoreset=True) def countdown(minutes): seconds = minutes * 60 - while seconds: - mins, secs = divmod(seconds, 60) - timer = f'{mins:02d}:{secs:02d}' - print(timer, end='\r') - time.sleep(1) - seconds -= 1 - print('Time is up!') + bar_format = Fore.GREEN + '{l_bar}{bar}| {remaining} seconds' + Style.RESET_ALL + with tqdm(total=seconds, desc='Time remaining', bar_format=bar_format, ncols=100) as pbar: + while seconds: + mins, secs = divmod(seconds, 60) + timer = f'{mins:02d}:{secs:02d}' + print(Fore.YELLOW + timer, end='\r' + Style.RESET_ALL) + time.sleep(1) + seconds -= 1 + pbar.update(1) + print(Fore.RED + '\nTime is up!' + Style.RESET_ALL) # Example usage: -countdown(1) # for a 25-minute work session -countdown(1) # for a 5-minute break +countdown(1) # for a 1-minute work session +countdown(1) # for a 1-minute break From 922676ee89cc03c3c0dbeaf89e23b4e0a9e89919 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:57:34 +0200 Subject: [PATCH 17/20] Update pomodoro.py Added a string to name the timer currently running --- Pomodoro Timer/pomodoro.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index e6e99cef..80270bad 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -5,7 +5,8 @@ # Initialize colorama init(autoreset=True) -def countdown(minutes): +def countdown(minutes, name): + print(name) seconds = minutes * 60 bar_format = Fore.GREEN + '{l_bar}{bar}| {remaining} seconds' + Style.RESET_ALL with tqdm(total=seconds, desc='Time remaining', bar_format=bar_format, ncols=100) as pbar: @@ -19,5 +20,5 @@ def countdown(minutes): print(Fore.RED + '\nTime is up!' + Style.RESET_ALL) # Example usage: -countdown(1) # for a 1-minute work session -countdown(1) # for a 1-minute break +countdown(1,"Work Session") # for a 1-minute work session +countdown(1,"Break") # for a 1-minute break From d25108614ef2ef07d731ac0f3b20accc1187158a Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:00:05 +0200 Subject: [PATCH 18/20] Update pomodoro.py Added second Example usage, the pomodoro timer will run for 25 min work session and 5 min break for infinity --- Pomodoro Timer/pomodoro.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index 80270bad..4bc0a45b 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -22,3 +22,9 @@ def countdown(minutes, name): # Example usage: countdown(1,"Work Session") # for a 1-minute work session countdown(1,"Break") # for a 1-minute break + +# Example use, running for infinity: + +while true: + countdown(25,"Work Session") + countdown(5, "Break") From 6b6749a8f3bece24e35f71e4cdcf1c4ad86f0138 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:01:39 +0200 Subject: [PATCH 19/20] Update pomodoro.py Changed true to True --- Pomodoro Timer/pomodoro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index 4bc0a45b..8c6382da 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -25,6 +25,6 @@ def countdown(minutes, name): # Example use, running for infinity: -while true: +while True: countdown(25,"Work Session") countdown(5, "Break") From 853e3ae51f858cdbaabee66aba9fbdd93910f1aa Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:04:17 +0200 Subject: [PATCH 20/20] Create App An Application --- Pomodoro Timer/App | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Pomodoro Timer/App diff --git a/Pomodoro Timer/App b/Pomodoro Timer/App new file mode 100644 index 00000000..e27f529c --- /dev/null +++ b/Pomodoro Timer/App @@ -0,0 +1,66 @@ +import sys +import time +from PyQt6.QtCore import QTimer, Qt +from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel +from PyQt6.QtGui import QFont +from colorama import init, Fore, Style + +# Initialize colorama +init(autoreset=True) + +class CountdownApp(QWidget): + def __init__(self): + super().__init__() + + self.initUI() + + def initUI(self): + self.layout = QVBoxLayout() + + self.label = QLabel("00:00") + self.label.setFont(QFont('Arial', 48)) + self.label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.layout.addWidget(self.label) + + self.work_button = QPushButton('Start Work Session') + self.work_button.clicked.connect(lambda: self.start_countdown(25, "Work Session")) + self.layout.addWidget(self.work_button) + + self.break_button = QPushButton('Start Break') + self.break_button.clicked.connect(lambda: self.start_countdown(5, "Break")) + self.layout.addWidget(self.break_button) + + self.setLayout(self.layout) + + self.setWindowTitle('Countdown Timer') + self.setGeometry(300, 300, 300, 200) + self.show() + + def start_countdown(self, minutes, session_name): + self.work_button.setDisabled(True) + self.break_button.setDisabled(True) + self.seconds = minutes * 60 + self.session_name = session_name + self.update_timer() + self.timer = QTimer(self) + self.timer.timeout.connect(self.update_timer) + self.timer.start(1000) + + def update_timer(self): + mins, secs = divmod(self.seconds, 60) + timer_text = f'{mins:02d}:{secs:02d}' + self.label.setText(timer_text) + + if self.seconds == 0: + self.timer.stop() + self.label.setText(f'{self.session_name} is over!') + + self.work_button.setDisabled(False) + self.break_button.setDisabled(False) + else: + self.seconds -= 1 + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = CountdownApp() + sys.exit(app.exec())