diff --git a/app.py b/app.py index e69de29..326dd1f 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 enter rock, paper, or scissors.") + +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!" + 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 main(): + user_score = 0 + computer_score = 0 + + while True: + user_choice = get_user_choice() + computer_choice = get_computer_choice() + print(f"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"Your score: {user_score}") + print(f"Computer's score: {computer_score}") + +if __name__ == "__main__": + main()