-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockpaper.py
More file actions
37 lines (30 loc) · 1.09 KB
/
Copy pathRockpaper.py
File metadata and controls
37 lines (30 loc) · 1.09 KB
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
import random
def get_computer_choice():
return random.choice(["rock", "paper", "scissors"])
def get_winner(player, computer):
if player == computer:
return "It's a tie!"
elif (
(player == "rock" and computer == "scissors") or
(player == "scissors" and computer == "paper") or
(player == "paper" and computer == "rock")
):
return "🎉 You win!"
else:
return "💻 Computer wins!"
def main():
print("✊🖐✌️ Welcome to Rock-Paper-Scissors!")
while True:
player_choice = input("Choose rock, paper, or scissors: ").strip().lower()
if player_choice not in ["rock", "paper", "scissors"]:
print("❌ Invalid choice. Try again.")
continue
computer_choice = get_computer_choice()
print(f"Computer chose: {computer_choice}")
print(get_winner(player_choice, computer_choice))
again = input("Play again? (yes/no): ").strip().lower()
if again != "yes":
print("Thanks for playing!")
break
if __name__ == "__main__":
main()