forked from Amal-nellanhi/Python-Mini-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissors.py
More file actions
88 lines (70 loc) · 2.38 KB
/
Copy pathrock_paper_scissors.py
File metadata and controls
88 lines (70 loc) · 2.38 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Project: Rock Paper Scissors Game
author:Bhavya K
Description:
Create a Rock-Paper-Scissors game where the user plays against the computer.
Requirements:
1. Ask the user to choose:
R for Rock
P for Paper
S for Scissors
2. The computer should randomly select its choice.
3. Display both choices using emojis if possible.
4. Determine the winner based on the rules.
5. Allow the user to play multiple rounds until they exit.
Sample Output:
Choose (R/P/S): R
You chose: Rock 🪨
Computer chose: Scissors ✂️
You win!
"""
import random
choices = {
'R': ("Rock", "🪨"),
'P': ("Paper", "📄"),
'S': ("Scissors", "✂️")
}
def get_computer_choice():
return random.choice(list(choices.keys()))
def determine_winner(user, computer):
if user == computer:
return "It's a tie!", None
elif (user == 'R' and computer == 'S') or \
(user == 'P' and computer == 'R') or \
(user == 'S' and computer == 'P'):
return "You win!", "user"
else:
return "Computer wins!", "computer"
def play_game():
print("🎮 Rock-Paper-Scissors Game 🎮")
user_score = 0
computer_score = 0
while True:
user_choice = input("\nChoose (R/P/S) or Q to quit: ").upper()
if user_choice == 'Q':
print("\nFinal Scores:")
print(f" You: {user_score}")
print(f" Computer: {computer_score}")
if user_score > computer_score:
print("You are the final winner!")
elif computer_score > user_score:
print("Computer is the final winner!")
else:
print("It's a final tie!")
print("Thanks for playing! 👋")
break
if user_choice not in choices:
print("Invalid choice! Please choose R, P, or S.")
continue
computer_choice = get_computer_choice()
user_name, user_emoji = choices[user_choice]
comp_name, comp_emoji = choices[computer_choice]
print(f"You chose: {user_name} {user_emoji}")
print(f"Computer chose: {comp_name} {comp_emoji}")
result, winner = determine_winner(user_choice, computer_choice)
print(result)
if winner == "user":
user_score += 1
elif winner == "computer":
computer_score += 1
play_game()