-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock paper sissor.py
32 lines (25 loc) · 1.09 KB
/
Rock paper sissor.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
import random
def rock_paper_scissors():
choices = ["rock", "paper", "scissors"]
while True:
computer_choice = random.choice(choices)
player_choice = None
while player_choice not in choices:
player_choice = input("Enter rock, paper, or scissors: ").lower()
if player_choice not in choices:
print("Please choose either rock, paper, or scissors!")
print(f"Computer chose: {computer_choice}")
print(f"You chose: {player_choice}")
if player_choice == computer_choice:
print("It's a tie!")
elif (player_choice == "rock" and computer_choice == "scissors") or \
(player_choice == "paper" and computer_choice == "rock") or \
(player_choice == "scissors" and computer_choice == "paper"):
print("You win!")
else:
print("You lose!")
user = input("Do you want to play again? (y/n): ").lower()
if user != 'y':
print("Thanks for playing!")
break
rock_paper_scissors()