/
Rock Paper Scissor.txt
46 lines (36 loc) · 1.53 KB
/
Rock Paper Scissor.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "It's a tie!"
elif user_choice == "rock":
return "You win!" if computer_choice == "scissors" else "Computer wins!"
elif user_choice == "paper":
return "You win!" if computer_choice == "rock" else "Computer wins!"
elif user_choice == "scissors":
return "You win!" if computer_choice == "paper" else "Computer wins!"
def main():
user_score = 0
computer_score = 0
print("Rock-Paper-Scissors Game")
while True:
print("\nChoose: rock, paper, or scissors")
user_choice = input("Your choice: ").lower()
if user_choice not in ["rock", "paper", "scissors"]:
print("Invalid choice. Please choose rock, paper, or scissors.")
continue
computer_choice = random.choice(["rock", "paper", "scissors"])
result = determine_winner(user_choice, computer_choice)
print(f"\nYou chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
print(result)
if result == "You win!":
user_score += 1
elif result == "Computer wins!":
computer_score += 1
print(f"Your score: {user_score} Computer score: {computer_score}")
play_again = input("\nDo you want to play again? (yes/no): ")
if play_again.lower() != "yes":
print("Thanks for playing!")
break
if __name__ == "__main__":
main()