-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
32 lines (25 loc) ยท 934 Bytes
/
app.py
File metadata and controls
32 lines (25 loc) ยท 934 Bytes
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 main():
print("Let's play Rock, Paper, Scissors!")
print("Enter your choice (1 for Rock, 2 for Paper, 3 for Scissors): ")
try:
user_choice = int(input("Your choice: "))
except ValueError:
print("Invalid input! Please enter a number between 1 and 3.")
return
if user_choice not in [1, 2, 3]:
print("Invalid choice! Please enter 1, 2, or 3.")
return
computer_choice = random.randint(1, 3)
choices = {1: "Rock", 2: "Paper", 3: "Scissors"}
print(f"Computer chose: {choices[computer_choice]}")
if user_choice == computer_choice:
print("It's a tie!")
elif (user_choice == 1 and computer_choice == 3) or \
(user_choice == 2 and computer_choice == 1) or \
(user_choice == 3 and computer_choice == 2):
print("You win!")
else:
print("Computer wins!")
if __name__ == "__main__":
main()