Guest User

Untitled

a guest
May 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # @Author: shubhambansal
  3. # @Date: 2018-05-21 00:26:10
  4. # @Last Modified by: shubhambansal
  5. # @Last Modified time: 2018-05-21 01:55:12
  6. import random
  7. choices = ['Rock', 'Paper', 'Scissors', 'Lizard', 'Spock']
  8.  
  9.  
  10.  
  11.  
  12.  
  13. def compare(player_choice, computer_choice):
  14. if player_choice == computer_choice:
  15. return 0
  16. else:
  17. if player_choice == 'Rock' and (computer_choice == 'Scissors' or computer_choice == 'Lizard'):
  18. return 1
  19. elif player_choice == 'Paper' and (computer_choice == 'Rock' or computer_choice == 'Spock'):
  20. return 1
  21. elif player_choice == 'Scissors' and (computer_choice == 'Paper' or computer_choice == 'Lizard'):
  22. return 1
  23. elif player_choice == 'Lizard' and (computer_choice == 'Spock' or computer_choice == 'Paper'):
  24. return 1
  25. elif player_choice == 'Spock' and (computer_choice == 'Scissors' or computer_choice == 'Rock'):
  26. return 1
  27. else:
  28. return -1
  29.  
  30.  
  31. def get_statment(c1, c2):
  32. if c1 == 'Spock' and c2 == 'Scissors':
  33. return '{} smashes {}'.format(c1, c2)
  34. elif c1 == 'Spock' and c2 == 'Rock':
  35. return '{} vaporizes {}'.format(c1, c2)
  36. elif c1 == 'Lizard' and c2 == 'Spock':
  37. return '{} poisons {}'.format(c1, c2)
  38. elif c1 == 'Lizard' and c2 == 'Paper':
  39. return '{} eats {}'.format(c1, c2)
  40. elif c1 == 'Rock' and c2 == 'Scissors':
  41. return '{} crushes {}'.format(c1, c2)
  42. elif c1 == 'Rock' and c2 == 'Lizard':
  43. return '{} crushes {}'.format(c1, c2)
  44. elif c1 == 'Paper' and c2 == 'Rock':
  45. return '{} covers {}'.format(c1, c2)
  46. elif c1 == 'Paper' and c2 == 'Spock':
  47. return '{} disproves {}'.format(c1, c2)
  48. elif c1 == 'Scissors' and c2 == 'Paper':
  49. return '{} cuts {}'.format(c1, c2)
  50. elif c1 == 'Scissors' and c2 == 'Lizard':
  51. return '{} decapitates {}'.format(c1, c2)
  52.  
  53.  
  54. print('Rock-Paper-Scissors-Lizard-Spock')
  55. tie = 0
  56. win = 0
  57. loss = 0
  58. while(True and (tie <=10 or win<=10 or loss <=10)):
  59. for i in range(0,len(choices)):
  60. print('{} {}'.format(i+1, choices[i]))
  61. player_choice = int(input('Make your choice: '))
  62. computer_choice = random.randint(0,4)
  63. result = compare(choices[player_choice - 1], choices[computer_choice])
  64. print('You chose: {}'.format(choices[player_choice-1]))
  65. print('Computer chose: {}'.format(choices[computer_choice]))
  66. if result != 0:
  67. if result == 1:
  68. print(get_statment(choices[player_choice - 1], choices[computer_choice]))
  69. win = win + 1
  70. else:
  71. print(get_statment(choices[computer_choice], choices[player_choice - 1]))
  72. loss = loss + 1
  73. else:
  74. tie = tie + 1
  75.  
  76. # paper disproves Spock!
  77. if(result == 1):
  78. print('You won!')
  79. #print('win = 1 loss= 0 ties= 0')
  80. elif(result == -1):
  81. print('You lose!')
  82. #print('win = 0 loss= 1 ties= 0')
  83. else:
  84. print('Tie!')
  85. #print('win = 0 loss= 0 ties= 1')
  86. print('win={} loss= {} ties= {}'.format(win, loss, tie))
Add Comment
Please, Sign In to add comment