#  Copyright (C) 2020, 2019 Girish M
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
# 
import random

choice = 'y'

while choice in ['y', 'Y', 'yes', 'YES']:
    rules = {'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper'}
    player = input('enter rock(r), paper(p), or scissors(s).: ')
    if player.startswith('r') or player.startswith('R'):
        player = 'rock'
    elif player.startswith('p') or player.startswith('P'):
        player = 'paper'
    elif player.startswith('s') or player.startswith('S'):
        player = 'scissors'
    else:
        print("Invalid input!")
        break
    print(player)

    cpu = random.choice(['rock', 'paper', 'scissors'])
    print(cpu)

    if player == cpu:
        print("it's a tie! no one wins")
    elif rules[player] == cpu:
        print('Player wins!')
    else:
        print('CPU wins!')

    choice = input('do you want to play again? (y/n): ')

