forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissors.py
More file actions
48 lines (37 loc) · 1.21 KB
/
Copy pathrock_paper_scissors.py
File metadata and controls
48 lines (37 loc) · 1.21 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
38
39
40
41
42
43
44
45
46
47
48
"""
Rock, Paper, Scissors Game (CLI Version)
Author: Your Name
"""
import random
def get_user_choice():
"""Prompt the user to enter their choice."""
choice = input("Enter your choice (rock, paper, scissors): ").lower()
if choice in ["rock", "paper", "scissors"]:
return choice
else:
print("Invalid choice! Please enter rock, paper, or scissors.")
return get_user_choice()
def get_computer_choice():
"""Randomly select computer's choice."""
options = ["rock", "paper", "scissors"]
return random.choice(options)
def decide_winner(player, computer):
"""Decide the winner based on the choices."""
if player == computer:
return "It's a draw!"
elif (
(player == "rock" and computer == "scissors")
or (player == "paper" and computer == "rock")
or (player == "scissors" and computer == "paper")
):
return "You win!"
else:
return "Computer wins!"
def main():
"""Main function to play the game."""
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"Computer chose: {computer_choice}")
print(decide_winner(user_choice, computer_choice))
if __name__ == "__main__":
main()