import random
cards = [11,2,3,4,5,6,7,8,9,10,10,10,10]
programrun = True
player = []
cpu = []
play = input("Do you want to play a game of Blackjack? Type 'y' or 'n': ")
while programrun:
if play == 'y':
cpupickup = random.choice(cards)
cpu.append(cpupickup)
for card in range(2):
pickup = random.choice(cards)
player.append(pickup)
else:
programrun = False
print(f" Your cards: {player}, current score: {sum(player)}")
print(f" Computer's first card: {cpu[0]}")
drawing = True
while drawing:
draw = input("Type 'y' to get another card, type 'n' to pass:")
if draw == 'n':
drawing = False
while sum(cpu) < 16:
cpupickup = random.choice(cards)
cpu.append(cpupickup)
print(f"Your final hand: {player}, final score : {sum(player)}")
print(f"Computer's final hand: {cpu}, final score : {sum(cpu)}")
if sum(player) > sum(cpu):
print("You win!")
elif sum(cpu) > 21:
print("Cpu went over, You win!")
elif sum(player) < sum(cpu):
print("you lose..")
elif sum(player) == sum(cpu):
print("Draw.")
elif sum(cpu) == 21:
print("Cpu get BlackJack, You lose..")
elif draw == 'y':
if sum(player) > 11:
cards[0] = 1
while sum(cpu) < 16:
cpupickup = random.choice(cards)
cpu.append(cpupickup)
pickup = random.choice(cards)
player.append(pickup)
print(f" Your cards : {player}, current score : {sum(player)}")
print(f" Computer's first card: {cpu[0]}")
if sum(player) > 21:
print(f" Your final cards : {player}, final score : {sum(player)}")
print(f" Computer's final hand: {cpu}, final score : {sum(cpu)}")
print("You went over. You lose..")
programrun - False
drawing = False
elif sum(cpu) > 21:
print(f" Your final cards : {player}, final score : {sum(player)}")
print(f" Computer's final hand: {cpu}, final score : {sum(cpu)}")
print("Cpu went over. You win!")
programrun = False
drawing = False
elif sum(cpu) == 21:
print(f" Your final cards : {player}, final score : {sum(player)}")
print(f" Computer's final hand: {cpu}, final score : {sum(cpu)}")
print("Cpu get BlackJack. You lose..")
programrun = False
drawing = False
https://namu.wiki/w/%EB%B8%94%EB%9E%99%EC%9E%AD(%EC%B9%B4%EB%93%9C%EA%B2%8C%EC%9E%84)
블랙잭(카드게임)
플레잉 카드 로 즐길 수 있는 카지노 게임이다. 21에 딜러보다 더 가까이 만들면 이기는 게임이다. 전 세계 어느
namu.wiki
'python study' 카테고리의 다른 글
| 파이썬 간단한 해시값 무결성 검사 (0) | 2025.09.21 |
|---|---|
| 파이썬 turtle로 거북이 경주시키기 (0) | 2024.09.29 |
| 파이썬으로 계산기 만들기 (0) | 2024.09.07 |
| Python으로 행맨게임 만들기 (0) | 2024.09.05 |
| 파이썬 공부 1 (0) | 2024.05.21 |