Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # @Author: shubhambansal
- # @Date: 2018-05-21 00:26:10
- # @Last Modified by: shubhambansal
- # @Last Modified time: 2018-05-21 01:55:12
- import random
- choices = ['Rock', 'Paper', 'Scissors', 'Lizard', 'Spock']
- def compare(player_choice, computer_choice):
- if player_choice == computer_choice:
- return 0
- else:
- if player_choice == 'Rock' and (computer_choice == 'Scissors' or computer_choice == 'Lizard'):
- return 1
- elif player_choice == 'Paper' and (computer_choice == 'Rock' or computer_choice == 'Spock'):
- return 1
- elif player_choice == 'Scissors' and (computer_choice == 'Paper' or computer_choice == 'Lizard'):
- return 1
- elif player_choice == 'Lizard' and (computer_choice == 'Spock' or computer_choice == 'Paper'):
- return 1
- elif player_choice == 'Spock' and (computer_choice == 'Scissors' or computer_choice == 'Rock'):
- return 1
- else:
- return -1
- def get_statment(c1, c2):
- if c1 == 'Spock' and c2 == 'Scissors':
- return '{} smashes {}'.format(c1, c2)
- elif c1 == 'Spock' and c2 == 'Rock':
- return '{} vaporizes {}'.format(c1, c2)
- elif c1 == 'Lizard' and c2 == 'Spock':
- return '{} poisons {}'.format(c1, c2)
- elif c1 == 'Lizard' and c2 == 'Paper':
- return '{} eats {}'.format(c1, c2)
- elif c1 == 'Rock' and c2 == 'Scissors':
- return '{} crushes {}'.format(c1, c2)
- elif c1 == 'Rock' and c2 == 'Lizard':
- return '{} crushes {}'.format(c1, c2)
- elif c1 == 'Paper' and c2 == 'Rock':
- return '{} covers {}'.format(c1, c2)
- elif c1 == 'Paper' and c2 == 'Spock':
- return '{} disproves {}'.format(c1, c2)
- elif c1 == 'Scissors' and c2 == 'Paper':
- return '{} cuts {}'.format(c1, c2)
- elif c1 == 'Scissors' and c2 == 'Lizard':
- return '{} decapitates {}'.format(c1, c2)
- print('Rock-Paper-Scissors-Lizard-Spock')
- tie = 0
- win = 0
- loss = 0
- while(True and (tie <=10 or win<=10 or loss <=10)):
- for i in range(0,len(choices)):
- print('{} {}'.format(i+1, choices[i]))
- player_choice = int(input('Make your choice: '))
- computer_choice = random.randint(0,4)
- result = compare(choices[player_choice - 1], choices[computer_choice])
- print('You chose: {}'.format(choices[player_choice-1]))
- print('Computer chose: {}'.format(choices[computer_choice]))
- if result != 0:
- if result == 1:
- print(get_statment(choices[player_choice - 1], choices[computer_choice]))
- win = win + 1
- else:
- print(get_statment(choices[computer_choice], choices[player_choice - 1]))
- loss = loss + 1
- else:
- tie = tie + 1
- # paper disproves Spock!
- if(result == 1):
- print('You won!')
- #print('win = 1 loss= 0 ties= 0')
- elif(result == -1):
- print('You lose!')
- #print('win = 0 loss= 1 ties= 0')
- else:
- print('Tie!')
- #print('win = 0 loss= 0 ties= 1')
- print('win={} loss= {} ties= {}'.format(win, loss, tie))
Add Comment
Please, Sign In to add comment