예시1
import random
lista = [1, 2, 3, 4, 5, 6]
random.shuffle(lista)
예시2
suits = ['Clover', 'Diamond', 'Heart', 'Spade']
rank = [str(i) for i in range(2, 11)]
rank = ['Ace'] + rank + ['Jack', 'Queen', 'King']
print(rank)
Deck = [] # 'Clover-Ace', 'Clover-2'
for s in suits:
for r in rank:
Deck.append(s + '-' + r)
score_list = [i + 1 for i in range(10)]
score_list = score_list + [10] * 3
score_list = score_list * 4
score_dict = dict(zip(Deck, score_list))
print(score_dict)
#print(Deck)
#print(score_list)
def score_hand(hand):
score = 0
for card in hand:
score = score + +score_dict[card]
return score
random.shuffle(Deck)
print(Deck)
print('Game Start\n')
random.shuffle(Deck)
print('Dealer Hands')
dealer_hand = [Deck.pop() for _ in range(2)]
print(dealer_hand, score_hand(dealer_hand))
print('\nPlayer Hands')
player_hand = [Deck.pop() for _ in range(2)]
print(player_hand, score_hand(player_hand))
if score_hand(player_hand) < 21:
ans = int(input('Deal(1) or Stop(0) :'))
if ans == 1:
player_hand.append(Deck.pop())
print(player_hand, score_hand(player_hand))
'백엔드개발자 준비하기 - 파이썬' 카테고리의 다른 글
[파이썬] numpy ndarray (0) | 2023.02.13 |
---|---|
[파이썬] numpy (0) | 2023.02.13 |
[파이썬] requests (0) | 2023.02.13 |
[파이썬] 마크다운 (0) | 2023.02.03 |
[파이썬] 클래스 (1) | 2023.02.03 |