Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.3 kB
4
Indexable
Never
import sys

answers = ['rock','paper','scissors']
attempts_player1 = 0
attempts_player2 = 0

# Get User input for player 1
print('Enter Value for Player 1: ')
player1 = input().lower()
while (player1 not in answers): 
    print('Player 1 input incorrect.') 
    print('Enter value for player 1 again: ')  
    player1 = input().lower()
    attempts_player1 += 1
    if (attempts_player1 == 3):
        sys.exit('Number of Incorrect attempts exceeded')

# Get User input for player 2
print('Enter Value for Player 2: ')
player2 = input().lower()
while (player2 not in answers): 
    print ('Player 2 input incorrect.')
    print('Enter value for player 2 again: ')   
    player2 = input().lower()
    attempts_player2 += 1
    if (attempts_player2 == 3):
        sys.exit('Number of Incorrect attempts exceeded')
    
# Game logic.  
# Note that the backslash is a line continuation for long expressions
if player1 == player2:
    print ('Players Tie')
elif (player1 == 'rock' and player2 == 'scissors') \
or (player1 == 'paper' and player2 == 'rock') \
or (player1 == 'scissors' and player2 == 'paper'):
    print('Player 1 Wins because they chose', player1)
else:
    print('Player 2 Wins because they chose', player2)