-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdd.py
More file actions
36 lines (28 loc) · 1.11 KB
/
dd.py
File metadata and controls
36 lines (28 loc) · 1.11 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
import random
# Define the valid choices
choices = ['rock', 'paper', 'scissors']
while True:
# Computer makes a random choice
computer = random.choice(choices)
# Get user input
user_choice = input("Enter your choice (rock, paper, scissors) or type 'quit' to exit: ").lower()
# Check if the user wants to quit
if user_choice == 'quit':
print("Thanks for playing! Goodbye!")
break
# Check if the user's input is valid
if user_choice not in choices:
print("Invalid input. Please choose rock, paper, or scissors.")
continue # Skip the rest of the loop and prompt the user again
# Display the computer's choice
print(f"Computer choice: {computer}")
# Determine the outcome
if computer == user_choice:
print("It's a tie")
elif (computer == 'rock' and user_choice == 'scissors') or \
(computer == 'paper' and user_choice == 'rock') or \
(computer == 'scissors' and user_choice == 'paper'):
print("You lose")
else:
print("You win")
print() # Add a blank line for better readability between rounds