Advertisement
AceScottie

rps

Jul 26th, 2018
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. import random
  2. count = 0
  3. score = 0
  4.  
  5. def check(your_choice, computer, score):
  6.     if your_choice == 0:
  7.         if computer == 1:
  8.             print("You Lost!")
  9.         elif computer == 2:
  10.             print("You Won")
  11.             score += 1
  12.         else:
  13.             print("Draw")
  14.     if your_choice == 1:
  15.         if computer == 2:
  16.             print("You Lost!")
  17.         elif computer == 0:
  18.             print("You Won")
  19.             score += 1
  20.         else:
  21.             print("Draw")
  22.     if your_choice == 2:
  23.         if computer == 0:
  24.             print("You Lost!")
  25.         elif computer == 1:
  26.             print("You Won")
  27.             score += 1
  28.         else:
  29.             print("Draw")
  30.     return score
  31.    
  32.    
  33. def get_computer_choice(dict, i):
  34.     for key, value in dict.iteritems():
  35.         if value == i:
  36.             return key
  37.            
  38. def main(score, count):
  39.     try:
  40.         dict = {"rock": 0, "paper": 1, "scissors": 2}
  41.         choice = raw_input('spelling is critical, choose rock paper or scissors:>')
  42.         computer = random.randint(0, 2)    
  43.         if choice in dict:
  44.             print("you chose %s and computer chose %s" %(choice, get_computer_choice(dict, computer)))
  45.             your_choice = dict[choice]
  46.             score = check(your_choice, computer, score)
  47.             print("current score = %s" %score)
  48.         else:
  49.             print('please check you spelling')
  50.         return score
  51.     except:
  52.         print("\r\nyour final score was %s out of %s games" %(score, count))
  53.  
  54. if __name__ == "__main__":
  55.     while True:
  56.         try:
  57.             count += 1
  58.             score = main(score, count)
  59.         except KeyboardInterrupt:
  60.             print("your final score was %s" %score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement