Simple Python Games: Rock-Paper-Scissors

Source code of r-p-s.py

from random import choice

options = {'r': 'rock', 'p': 'paper', 's': 'scissors'}
beats = {'r': 's', 'p': 'r', 's': 'p'}

print()
print('Rock-Paper-Stone Game with computer (Ctrl+C to exit)')
print()

while True:
    c_choice = choice(list(options.keys()))
    p_choice = input('Enter your choice ([R]ock, [P]aper, [S]cissors): ').lower()

    if p_choice not in options:
        print(p_choice.upper(), 'is not a valid option.')
        continue

    print('You chose', options[p_choice].upper())
    print('Computer chose', options[c_choice].upper())

    if p_choice == c_choice:
        print('It\'s a draw.')
    elif beats[p_choice] == c_choice:
        print('You win!')
    else:
        print('Computer wins!')

Tips for improvement

  1. Add some dramatic pause before the evaluation (hint: time.sleep())
  2. Add an exit option instead of Ctrl+C
  3. Count the scores

Download

Source code of Rock-Paper-Scissors (r-p-s.py).