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()) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py new file mode 100644 index 00000000..8c6382da --- /dev/null +++ b/Pomodoro Timer/pomodoro.py @@ -0,0 +1,30 @@ +import time +from tqdm import tqdm +from colorama import init, Fore, Style + +# Initialize colorama +init(autoreset=True) + +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: + 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,"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") 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/README.md b/README.md index fc120580..a83d6daa 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! | diff --git a/Rock Paper Scissor/rps.py b/Rock Paper Scissor/rps.py index 90f3fd39..f211c91d 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,56 +28,55 @@ 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 # 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("Computer choice is: " + 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() 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() diff --git a/Rock Paper Scissors -New/README.md b/Rock Paper Scissors -New/README.md new file mode 100644 index 00000000..7dce0873 --- /dev/null +++ b/Rock Paper Scissors -New/README.md @@ -0,0 +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. + diff --git a/Rock Paper Scissors -New/rps.py b/Rock Paper Scissors -New/rps.py new file mode 100644 index 00000000..1a488b17 --- /dev/null +++ b/Rock Paper Scissors -New/rps.py @@ -0,0 +1,90 @@ +import random + +choices = ["rock", "paper", "scissors", "lizard", "spock"] + +def get_user_choice(): + 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(): + 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!") + + while True: + 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}") + + 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'.") + + if play_again != "y": + print("Thanks for playing!") + break + +if __name__ == "__main__": + play_game()