My code implementing rock, paper and scissors in Python, using dicts to hold choices.
import random
choices = ['rock', 'paper', 'scissors']
def choice():
player_choice = raw_input('Choose rock, paper or scissors: ')
if player_choice.lower() in choices:
computer_choice = random.choice(choices)
play(player_choice, computer_choice)
else:
choice()
def play(p_choice, c_choice):
win_table = {'rock' : {'rock':'It was a Tie', 'paper':'You Lose', 'scissors':'You Win'},
'paper' : {'rock':'You Win', 'paper':'It was a Tie', 'scissors':'You Lose'},
'scissors' : {'rock':'You Lose', 'paper':'You Win', 'scissors':'It was a Tie'}}
print 'Computer chose', c_choice
print win_table[p_choice][c_choice]
new = raw_input('Play again ? (Y/N): ')
if new.lower() == 'y':
choice()
else:
print 'Have a nice day !'
choice()
win_table
dictionary names are player choices and dictionary keys are computer choices, seems more efficient to me. I haven't run any memory usage tests, though.