Skip to content

Instantly share code, notes, and snippets.

@dumpmycode
Last active February 26, 2016 07:03
Show Gist options
  • Save dumpmycode/9dfdc07ba479676ff56c to your computer and use it in GitHub Desktop.
Save dumpmycode/9dfdc07ba479676ff56c to your computer and use it in GitHub Desktop.
practicepython.org - Rock Paper Scissor single player game
#! /usr/bin/env python
# Author: OscarP
# A single player jankenpon game using randint to generate computer's hand.
# Please feel free to revise.
from random import randint
def convert(choice):
if choice == '1':
return 'rock'
elif choice == '2':
return 'scissor'
elif choice == '3':
return 'paper'
else:
print('Enter 1, 2 or 3 only please.\nfuck this shit im out!')
exit(0)
def win():
print('You win!')
print('\033[1;31m{}\033[1;m vs {}'.format(player,computer))
def lose():
print('You lost.')
print('\033[1;31m{}\033[1;m vs {} '.format(player, computer))
def jankenpon(player, computer):
if player == computer:
print ('Its a tie!')
print('\033[1;31m{}\033[1;m vs {} '.format(player, computer))
elif player == 'rock':
if computer == 'scissor':
win()
else:
lose()
elif player == 'scissor':
if computer == 'paper':
win()
else:
lose()
else:
if computer == 'rock':
win()
else:
lose()
newgame = raw_input('Do you want to play JanKenPon? (y/n)')
while newgame == 'y':
computer = str(randint(1,3))
player = raw_input('Player 1 enter your hand (1: rock, 2: scissor, 3: paper) = ')
computer = convert(computer)
player = convert(player)
jankenpon(player, computer)
newgame = raw_input('Do you want to keep playing JanKenPon? (y/n)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment