From dcc8d314941734e3087fca861a6ebe245611142f Mon Sep 17 00:00:00 2001 From: "Mr. Algorithm" <148683640+ravixalgorithm@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:04:44 +0000 Subject: [PATCH] Main --- app.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/app.py b/app.py index e69de29..f159eee 100644 --- a/app.py +++ b/app.py @@ -0,0 +1,49 @@ +import random + +def get_user_choice(): + while True: + user_choice = input("Enter your choice (rock, paper, or scissors): ").lower() + if user_choice in ["rock", "paper", "scissors"]: + return user_choice + else: + print("Invalid choice. Please try again.") + +def get_computer_choice(): + return random.choice(["rock", "paper", "scissors"]) + +def determine_winner(user_choice, computer_choice): + if user_choice == computer_choice: + return "Tie" + elif (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 "You lose" + +def play_game(): + user_score = 0 + computer_score = 0 + + while True: + user_choice = get_user_choice() + computer_choice = get_computer_choice() + + print(f"You chose: {user_choice}") + print(f"The computer chose: {computer_choice}") + + result = determine_winner(user_choice, computer_choice) + print(result) + + if result == "You win": + user_score += 1 + elif result == "You lose": + computer_score += 1 + + play_again = input("Do you want to play again? (yes/no): ").lower() + if play_again != "yes": + break + + print(f"Final score: You {user_score} - Computer {computer_score}") + +play_game()