import random
def play():
user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n")
computer = random.choice(['r', 'p', 's'])
if user == computer:
return "It's a tie"
if is_win(user, computer):
return 'You won!'
return 'You lost!'
def is_win(player, opponent):
if(player == 'r' and opponent == 's') or (player == 's' and opponent == 'p')\
or (player == 'p' and opponent == 'r'):
return True
# r > s, s > p, p > r,
Hi everyone,
I’m new here. I’m also new to python, currently practicing coding. can you help me with this code? If i run it, the output is blank. Thanks
>Solution :
It seems like your code is missing a main function that calls the play function and handles the output. Additionally, there are some issues with the indentation and structure of your code.
import random
def play():
user = input("What's your choice? 'r' for rock, 'p' for paper, 's'
for scissors\n")
computer = random.choice(['r', 'p', 's'])
if user == computer:
return "It's a tie"
if is_win(user, computer):
return 'You won!'
return 'You lost!'
def is_win(player, opponent):
if (player == 'r' and opponent == 's') or (player == 's' and
opponent == 'p') or (player == 'p' and opponent == 'r'):
return True
result = play()
print(result)