# rockpaperscissors.py

Sep 10th, 2014
307
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #rockpaperscissors.py
2. #Rock Paper Scissors by D10d3
3. #Goal:
4. #    Ask the player if they pick rock paper or scissors
5. #    Have the computer chose its move
6. #    Compare the choices and decide who wins
7. #    Print the results
8. #Sub goals:
9. #    Let the player play again
10. #    Keep a record of the score e.g. (Player: 3 / Computer: 6)
11. #---------------------------------------------------------------------------------------------
12.
13. #adds the ability to create random choices. example:
14. #foo = ['a', 'b', 'c', 'd', 'e']
15. #print(random.choice(foo))
16. import random
17.
18. def p_shoot(): #Player chooses move
19.     print "What move would you like to play?"
21.     print "(R) Rock"
22.     print "(P) Paper"
23.     print "(S) Scissors"
24.     p_choice = raw_input('>')
25.     p_choice = p_choice.lower()
26.     if p_choice == 'r':
27.         p_move = "Rock"
28.     elif p_choice == 'p':
29.         p_move = "Paper"
30.     elif p_choice == 's':
31.         p_move = "Scissors"
32.     print "You played %s" % p_move
33.     return p_move
34.
35. def c_shoot(): #generate computer move
36.     c_hand = ['Rock', 'Paper', 'Scissors']
37.     throw = random.choice(c_hand)
38.     return throw
39.
40. def compair(p,c): # my sorry excuse for "logic"
41.     if p == "Rock" and c == "Rock":
42.         winner = "Tie"
43.     elif p == "Rock" and c == "Paper":
44.         winner = "Computer"
45.     elif p == "Rock" and c == "Scissors":
46.         winner = "Player"
47.     elif p == "Paper" and c == "Rock":
48.         winner = "Computer"
49.     elif p == "Paper" and c == "Paper":
50.         winner = "Tie"
51.     elif p == "Paper" and c == "Scissors":
52.         winner = "Computer"
53.     elif p == "Scissors" and c == "Rock":
54.         winner = "Computer"
55.     elif p == "Scissors" and c == "Paper":
56.         winner = "Player"
57.     elif p == "Scissors" and c == "Scissors":
58.         winner = "Tie"
59.     return winner
60.
61. #Begin Game and setup variables
62. print "Hi there, let's play Rock Paper Scissors!"
63. playing = True
64. c_wins = 0
65. p_wins = 0
66. ties = 0
67.
68. #Begin game Loop
69. while playing:
70.     p_move = p_shoot()
71.     c_move = c_shoot()
72.     winner = compair(p_move,c_move) #declare winner
73.     print "Computer played %s" % c_move
74.     if winner == "Tie":
75.         print "The match is tied!"
76.         ties = ties + 1
77.     elif winner == "Player":
78.         print "The Player is the winner!"
79.         p_wins = p_wins + 1
80.     elif winner == "Computer":
81.         print "The Computer is the winner!"
82.         c_wins = c_wins + 1
83.     #print scores
84.     print "Scores:"
85.     print "Player  : %d" % p_wins
86.     print "Computer: %d" % c_wins
87.     print "Ties    : %d" % ties
88.     #ask player if they'd like to play again
89.     print "Would you like to play again? (Y/N)"
90.     again = raw_input('>')
91.     again = again.lower()
92.     if again == "n":
93.         print "Thank you for playing"
94.         quit()
RAW Paste Data