When the input is 'r' it works perfectly but when the input is 'p' or 'r' it just adds up these two letters to the word 'scissors´ from the input phrase
import random
def play():
user = input("'r' for rock, 'p' for paper, 's' for scissors")
computer = random.choice(['r','p','s'])
if user == computer:
return 'It`s a tie!'
# r > s, s > p, p > r
if is_win(user, computer):
return 'You won!'
return 'You lost'
def is_win(player, opponent):
#return true if player wins
#r>s, s>p, p>r
if(player == 'r' and opponnent == 's') or (player == 's' and opponnent == 'p') or \
(player == 'p' and opponnent == 'r'):
return True
Aucun commentaire:
Enregistrer un commentaire