def rock_paper_scissors_lizard_spock(player1, player2):
# each variable stores what it can defeat
scissors = ['paper','lizard']
rock = ['lizard', 'scissors']
paper = ['rock','spock']
lizard = ['spock','paper']
spock = ['scissors','rock']
if str(player2) in player1:
print('player 1 wins')
rock_paper_scissors_lizard_spock('rock','spock')
Can I use the arguments to the function declared above to refer to a particular variable?
jpp
166k37 gold badges301 silver badges363 bronze badges
1 Answer 1
Short answer, no. Use a dictionary.
def rock_paper_scissors_lizard_spock(player1, player2):
# each variable stores what it can defeat
mapper = {'scissors': ['paper', 'lizard'],
'rock': ['lizard', 'scissors'],
'paper': ['rock', 'spock'],
'lizard': ['spock', 'paper'],
'spock': ['scissors', 'rock']}
print('player %s wins' %(1 if player2 in mapper[player1] else 2))
rock_paper_scissors_lizard_spock('paper', 'rock') # player 1 wins
answered Jan 27, 2018 at 4:50
jpp
166k37 gold badges301 silver badges363 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
d['rock'] = ['lizard', 'scissors']