본문 바로가기

python study

파이썬으로 블랙잭 만들기

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