Advertisement
Peaser

rock paper scissors

Jul 14th, 2015
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import random, operator
  2.  
  3. def main():
  4.   bestof = int(raw_input("(odd number) - Best of :"))
  5.   if not bestof % 2: raise Exception, "Make that shit an odd number"
  6.   print "Playing best of %d" % bestof
  7.   calls = {
  8.   # key's value is what key beats
  9.     "rock": "scissors",
  10.     "paper": "rock",
  11.     "scissors": "paper"
  12.   }
  13.   points = {
  14.    "You": 0,
  15.    "Computer": 0
  16.   }
  17.   for turn in range(1, bestof + 1):
  18.     print "Turn %d/%d" % (turn, bestof)
  19.     yourCall = raw_input("Make a call (rock, paper, scissors) :").lower()
  20.     if yourCall not in calls: raise Exception, "Fuck you, play the game right."
  21.     themCall = random.choice(calls.keys())
  22.     print "You: %s" % yourCall
  23.     print "Computer: %s" % themCall
  24.     if yourCall == themCall:
  25.       print "Tie! No points gained."
  26.     elif themCall == calls[yourCall]:
  27.       print "You win that turn! Point to You!"
  28.       points["You"] += 1
  29.     else:
  30.       print "Computer wins that turn! Point to Computer!"
  31.       points["Computer"] += 1
  32.   if len(list(set(points.values()))) == 1:
  33.     print "Draw! NOBODY WINS"
  34.   else:
  35.     print "!!!!Winner is %s!!!!" % max(points.iteritems(), key=operator.itemgetter(1))[0]
  36.  
  37. if __name__ == '__main__':
  38.   main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement