Python card game two players
Create a simple card game that deals two players three cards each. The player with the highest card wins. If there is a tie, then compare the second highest card and, if necessary, the third highest. If all three cards have the same value, then the game is a draw.
player1 = []
player2 = []
for i in range(3):
shuffle(d)
player1.append((d[0]['value'], d[0]['suit']))
shuffle(d)
player2.append((d[0]['value'], d[0]['suit']))
for i in range(len(player1)):
if player1[i][0] > player2[i][0]:
print('Player 1 win\'s!')
break
elif player1[i][0] < player2[i][0]:
print('Player 2 win\'s!')
break
else:
pass
print(player1)
print(player2)
from random import shuffle
d = [{'value':i, 'suit':c} for c in ['spades', 'clubs', 'hearts', 'diamonds'] for i in range(2, 15)]
d = [{'value':i, 'suit':c} for c in ['spades', 'clubs', 'hearts', 'diamonds'] for i in range(2, 15)]
player1 = []
player2 = []
for i in range(3):
shuffle(d)
player1.append((d[0]['value'], d[0]['suit']))
shuffle(d)
player2.append((d[0]['value'], d[0]['suit']))
for i in range(len(player1)):
if player1[i][0] > player2[i][0]:
print('Player 1 win\'s!')
break
elif player1[i][0] < player2[i][0]:
print('Player 2 win\'s!')
break
else:
pass
print(player1)
print(player2)
SOLUTION
Player 2 win's!
[(2, 'clubs'), (2, 'diamonds'), (8, 'hearts')]
[(2, 'hearts'), (7, 'clubs'), (13, 'hearts')]
[(2, 'clubs'), (2, 'diamonds'), (8, 'hearts')]
[(2, 'hearts'), (7, 'clubs'), (13, 'hearts')]
Коментари
Постави коментар