-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROCK PAPER SCISSORS TASK3.py
51 lines (38 loc) · 1.6 KB
/
ROCK PAPER SCISSORS TASK3.py
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
47
48
49
50
51
# Rock-Paper-Scissors Game
import random
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 == 'scissors' and computer_choice == 'paper') or \
(user_choice == 'paper' and computer_choice == 'rock'):
return "You win!"
else:
return "You lose!"
def play_game():
user_score = 0
computer_score = 0
play_again = True
while play_again:
print("\nWelcome to Rock-Paper-Scissors Game")
print("Please choose: rock, paper, or scissors")
user_choice = input("Your choice: ").lower()
if user_choice not in ['rock', 'paper', 'scissors']:
print("Invalid choice. Please try again.")
continue
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
print(f"\nYou chose: {user_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
print(f"\nScores -> You: {user_score} | Computer: {computer_score}")
play_again_input = input("Do you want to play again? (yes/no): ").lower()
play_again = play_again_input == 'yes'
print("\nThanks for playing! Final scores:")
print(f"You: {user_score} | Computer: {computer_score}")
play_game()