-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrps.py
69 lines (62 loc) · 2.35 KB
/
rps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
__author__ = 'Akshay'
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 25 18:57:17 2014
"""
import random
class Rps():
"""
A simple game of rock papers and scissors.Rock-paper-scissors is a hand game usually played by two people,
where players simultaneously form one of three shapes with an outstretched hand. The "rock" beats scissors,
the "scissors" beat paper and the "paper" beats rock; if both players throw the same shape, the game is tied.
"""
def __init__(self):
values = ['rock', 'paper', 'scissors']
player_values = raw_input('Show the shape of your fist')
if player_values in values:
computer_values = self.randomize(values)
return self.result(player_values, computer_values)
else:
'Enter a valid value'
self.replay()
def replay(self):
option = raw_input('Do you want to play again ? (y/n)')
option = option.lower()
if option == 'y':
return self.__init__()
elif option == 'n':
pass
else:
print "enter y or n"
self.replay()
def randomize(self, computer_values):
random.shuffle(computer_values)
return computer_values[0]
def result(self, player_value, computer_values):
if player_value == computer_values:
print "Draw"
self.replay()
else:
if player_value == 'rock':
if computer_values == 'paper':
print "You Lose, computer chose %s" % computer_values
self.replay()
else:
print "You win computer chose %s" % computer_values
self.replay()
elif player_value == 'paper':
if computer_values == 'scissors':
print "You lose computer chose %s" % computer_values
self.replay()
else:
print "You win computer chose %s" % computer_values
self.replay()
elif player_value == 'rock':
if computer_values == 'paper':
print "you lose computer chose %s" % computer_values
self.replay()
else:
print "You win computer chose %s" % computer_values
self.replay()
a = Rps()
a.__init__