-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissorsGame.py
More file actions
30 lines (22 loc) · 895 Bytes
/
RockPaperScissorsGame.py
File metadata and controls
30 lines (22 loc) · 895 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
import random
print('Welcome to the Rock, Paper, Scissors Game!')
print("Type 'rock', 'paper', or 'scissors' to play. Type 'quit' to exit.")
choice=['rock', 'paper', 'scissors']
while True:
user_choice = input('Enter your choice: ').lower()
if user_choice=='quit':
print('Thank you for playing!')
break
if user_choice not in choice:
print('Invalid choice. Please enter rock, paper, or scissors.')
continue
computer_choice = random.choice(choice)
print(f'Computer chose: {computer_choice}')
if user_choice == computer_choice:
print("It's a tie!")
elif (user_choice == 'rock' and computer_choice == 'scissors') or \
(user_choice == 'paper' and computer_choice == 'rock') or \
(user_choice == 'scissors' and computer_choice == 'paper'):
print('You win!')
else:
print('You lose!')