-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock,Paper and Scissors.py
38 lines (33 loc) · 1.51 KB
/
Rock,Paper and Scissors.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
import random
def game():
while True:
user_choice = input("Enter a choice (rock, paper, scissors): ").lower()
while user_choice not in ["rock", "paper", "scissors"]:
user_choice = input("Invalid input. Enter a choice (rock, paper, scissors): ").lower()
possible_choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(possible_choices)
print(f"\nYou chose {user_choice}, computer chose {computer_choice}.\n")
if user_choice == computer_choice:
print(f"Both players selected {user_choice}. It's a tie!")
elif user_choice == "rock":
if computer_choice == "scissors":
print("Rock smashes scissors! You win!")
else:
print("Paper covers rock! You lose.")
elif user_choice == "paper":
if computer_choice == "rock":
print("Paper covers rock! You win!")
else:
print("Scissors cuts paper! You lose.")
elif user_choice == "scissors":
if computer_choice == "paper":
print("Scissors cuts paper! You win!")
else:
print("Rock smashes scissors! You lose.")
play_again = input("Play again? (yes/no): ").lower()
while play_again not in ["yes", "no"]:
play_again = input("Invalid input. Play again? (yes/no): ").lower()
if play_again != "yes":
break
if __name__ == "__main__":
game()