diff --git a/rock-paper-scissors.py b/rock-paper-scissors.py new file mode 100644 index 0000000..1f84e96 --- /dev/null +++ b/rock-paper-scissors.py @@ -0,0 +1,54 @@ +import random + +def play_round(): + choices = ["rock", "paper", "scissors"] + computer_choice = random.choice(choices) + + while True: + user_choice = input("Enter rock, paper, or scissors: ").lower() + if user_choice in choices: + break + else: + print("Invalid choice. Please enter rock, paper, or scissors.") + + print(f"You chose: {user_choice}") + print(f"Computer chose: {computer_choice}") + + if user_choice == computer_choice: + print("It's a tie!") + return 0 + elif ( + (user_choice == "rock" and computer_choice == "scissors") + or (user_choice == "paper" and computer_choice == "rock") + or (user_choice == "scissors" and computer_choice == "paper") + ): + print("You win!") + return 1 + else: + print("You lose!") + return -1 + +def main(): + user_score = 0 + computer_score = 0 + + print("Welcome to Rock, Paper, Scissors!") + + while True: + result = play_round() + if result == 1: + user_score += 1 + elif result == -1: + computer_score += 1 + + print(f"Your score: {user_score}, Computer score: {computer_score}") + + play_again = input("Play again? (yes/no): ").lower() + if play_again != "yes": + break + + print("Thanks for playing!") + print(f"Final score. Your score: {user_score}, Computer score: {computer_score}") + +if __name__ == "__main__": + main() diff --git a/simple-calculator.py b/simple-calculator.py new file mode 100644 index 0000000..8153f67 --- /dev/null +++ b/simple-calculator.py @@ -0,0 +1,21 @@ +num1 = float(input("Enter first number: ")) +num2 = float(input("Enter second number: ")) +operator = input("Enter operator (+, -, *, /): ") + +if operator == '+': + result = num1 + num2 +elif operator == '-': + result = num1 - num2 +elif operator == '*': + result = num1 * num2 +elif operator == '/': + if num2 == 0: + print("Error: Division by zero") + else: + result = num1 / num2 +else: + print("Invalid operator") + result = None + +if result is not None: + print("Result:", result)