0
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
asked Jan 27, 2018 at 4:45
3
  • is this possible? any suggestions? I'm pretty new. Commented Jan 27, 2018 at 4:46
  • You can use a dict of lists. So d['rock'] = ['lizard', 'scissors'] Commented Jan 27, 2018 at 4:50
  • @MichaelRisling, did the below answer help? if so, feel free to accept the answer (tick on the left), so other users can see a tested answer. Commented Feb 4, 2018 at 19:04

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.