# Calculating points

unknown
python
10 days ago
3.6 kB
4
Indexable
Never
```# Create a deck of cards
deck = [('A', suit,11) for suit in ('hearts', 'diamonds', 'spades', 'clubs')] + \
[(rank, suit,rank) for rank in range(8, 11) for suit in ('hearts', 'diamonds', 'spades', 'clubs')] + \
[('J', suit,10) for suit in ('hearts', 'diamonds', 'spades', 'clubs')] + \
[('Q', suit,10) for suit in ('hearts', 'diamonds', 'spades', 'clubs')] + \
[('K', suit,10) for suit in ('hearts', 'diamonds', 'spades', 'clubs')] + \
[(7, suit,7) for suit in ('hearts', 'diamonds', 'spades')] + \
[(7,'clubs',11)]

# Calculating points
def calculate_points(hand):
first_card = hand[0]
second_card = hand[1]
third_card = hand[2]

if( first_card[0]==second_card[0] and second_card[0]==third_card[0]):

if(first_card[0]==7):
return 34

return first_card[2] +second_card[2] +third_card[2]

result =0

if( (first_card[0]==7 and first_card[1]=='clubs' and second_card[1]==third_card[1]) or (second_card[0]==7 and second_card[1]=='clubs' and first_card[1]==third_card[1]) or (third_card[0]==7 and third_card[1]=='clubs' and first_card[1]==second_card[1])):
return first_card[2]+second_card[2]+third_card[2]

if((first_card[0]==7 and first_card[1]=='clubs' and second_card[0]==third_card[0]) or (second_card[0]==7 and second_card[1]=='clubs' and first_card[0]==third_card[0]) or (third_card[0]==7 and third_card[1]=='clubs' and first_card[0]==second_card[0])):
return first_card[2]+ second_card[2]+third_card[2]

if ((first_card[0]=='A' and second_card[0]=='A') or (second_card[0]=='A' and third_card[0]=='A') or (first_card[0]=='A' and third_card[0]=='A')):
return 22

if ((first_card[0] == 7 and second_card[0] == 7) or (second_card[0] == 7 and third_card[0] == 7) or (
first_card[0] == 7 and third_card[0] == 7)):
return 23

if (first_card[1] == second_card[1] and second_card[1] ==third_card[1]):

result = first_card[2] +second_card[2] +third_card[2]

elif (first_card[1]==second_card[1] and third_card[1] != second_card[1]):
result= max(first_card[2] +second_card[2],BiggestNumber(hand))

elif (first_card[1]==third_card[1] and first_card[1] != second_card[1]):
result =max(first_card[2] +third_card[2],BiggestNumber(hand))

elif (second_card[1]== third_card[1] and third_card[1] !=first_card[1]):
result = max(second_card[2] +third_card[2], BiggestNumber(hand))

else:
result = BiggestNumber(hand)

return result

def BiggestNumber(hand):
first_card= hand[0]
second_card = hand[1]
third_card = hand[2]

if (first_card[0]==7 and first_card[1]=='clubs'):
if(second_card[2]>=third_card[2]):
return first_card[2]+second_card[2]
else:
return first_card[2]+ third_card[2]

elif(second_card[0]==7 and second_card[1]=='clubs'):
if(first_card[2] >= third_card[2]):
return first_card[2]+second_card[2]
else:
return second_card[2]+third_card[2]

elif(third_card[0]==7 and third_card[1]=='clubs'):
if (second_card[2] >= first_card[2]):
return second_card[2]+third_card[2]
else:
return first_card[2]+third_card[2]

if ( first_card[2] >= second_card[2] and third_card[2] <= first_card[2]):
sum = first_card[2]
elif (third_card[2] >= first_card[2] and third_card[2] >= second_card[2]):
sum = third_card[2]
else:
sum = second_card[2]

return sum```