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!')
Source code of Rock-Paper-Scissors (r-p-s.py).