View difference between Paste ID: RujrGfLM and Vyf5XWxD
SHOW: | | - or go back to the newest paste.
1-
#rockpaperscissors.py
1+
2
#Goal:
3
#    Ask the player if they pick rock paper or scissors
4
#    Have the computer chose its move
5
#    Compare the choices and decide who wins
6
#    Print the results
7
#Sub goals:
8
#    Let the player play again
9
#    Keep a record of the score e.g. (Player: 3 / Computer: 6)
10
#---------------------------------------------------------------------------------------------
11
12
#adds the ability to create random choices. example:
13
#foo = ['a', 'b', 'c', 'd', 'e']
14
#print(random.choice(foo))
15
import random
16
17
def p_shoot(): #Player chooses move
18
	valid = False
19-
	print "What move would you like to play?"
19+
	while not valid:
20-
	print "type your selection:"
20+
		print """
21-
	print "(R) Rock"
21+
	What move would you like to play?
22-
	print "(P) Paper"
22+
	Type your selection:
23-
	print "(S) Scissors"
23+
	(R) Rock
24-
	p_choice = raw_input('>')
24+
	(P) Paper
25-
	p_choice = p_choice.lower()
25+
	(S) Scissors"""
26-
	if p_choice == 'r':
26+
		p_choice = raw_input('>')
27-
		p_move = "Rock"
27+
		p_choice = p_choice.lower()
28-
	elif p_choice == 'p':
28+
		if p_choice == 'r':
29-
		p_move = "Paper"
29+
			p_move = "Rock"
30-
	elif p_choice == 's':
30+
			valid = True
31-
		p_move = "Scissors"
31+
		elif p_choice == 'p':
32
			p_move = "Paper"
33
			valid = True
34
		elif p_choice == 's':
35
			p_move = "Scissors"
36
			valid = True
37
	print "You played %s" % p_move
38
	return p_move
39
40
def c_shoot(): #generate computer move
41-
	if p == "Rock" and c == "Rock":
41+
42
	throw = random.choice(c_hand)
43-
	elif p == "Rock" and c == "Paper":
43+
44-
		winner = "Computer"
44+
45-
	elif p == "Rock" and c == "Scissors":
45+
46-
		winner = "Player"
46+
	if p == c:
47-
	elif p == "Paper" and c == "Rock":
47+
48-
		winner = "Computer"
48+
	elif p == "Rock":
49-
	elif p == "Paper" and c == "Paper":
49+
		if c == "Paper":
50
			winner = "Computer"
51-
	elif p == "Paper" and c == "Scissors":
51+
		else:
52-
		winner = "Computer"
52+
			winner = "Player"
53-
	elif p == "Scissors" and c == "Rock":
53+
	elif p == "Paper":
54-
		winner = "Computer"
54+
		if c == "Scissors":
55-
	elif p == "Scissors" and c == "Paper":
55+
			winner = "Computer"
56-
		winner = "Player"
56+
		else:
57-
	elif p == "Scissors" and c == "Scissors":
57+
			winner = "Player"
58
	elif p == "Scissors":
59
		if c == "Rock":
60
			winner = "Computer"
61-
#Begin Game and setup variables
61+
		else:
62
			winner = "Player"
63
	return winner		
64
65
#Begin Game and set up variables
66
print "Hi there, let's play Rock Paper Scissors!"	
67
playing = True
68
c_wins = 0
69
p_wins = 0
70
ties = 0
71
72
#Begin game Loop
73
while playing:
74
	p_move = p_shoot()
75
	c_move = c_shoot()
76
	winner = compair(p_move,c_move) #declare winner
77
	print "Computer played %s" % c_move
78
	if winner == "Tie":
79
		print "The match is tied!"
80
		ties = ties + 1
81
	elif winner == "Player":
82
		print "The Player is the winner!"
83
		p_wins = p_wins + 1
84
	elif winner == "Computer":
85
		print "The Computer is the winner!"
86
		c_wins = c_wins + 1
87
	#print scores
88
	print "Scores:"
89-
	print "Would you like to play again? (Y/N)"
89+
90-
	again = raw_input('>')
90+
91-
	again = again.lower()
91+
92-
	if again == "n":
92+
93-
		print "Thank you for playing"
93+
	valid = False
94-
		quit()
94+
	while not valid:
95
		print "Would you like to play again? (Y/N)"
96
		again = raw_input('>')
97
		again = again.lower()
98
		if again == "n":
99
			print "Thank you for playing"
100
			quit()
101
		elif again =="y":
102
			valid = True