Demo entry 6633956

s

   

Submitted by anonymous on Aug 07, 2017 at 14:32
Language: Python 3. Code size: 2.3 kB.

import random

class Klasse

def cpu():
    pass


def player():
    pass


def card_gen(n): #Not finalised yet because multiple duplictes of one colour are possible. Solution: for-loop in for-loop
    color_pallette = ["Herz-", "Pik-", "Caro-", "Kreuz-"]
    numbr_pallette = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "B", "D", "K", "A"]    
    card_list = []
    i = 0
    while i < n:
        i += 1
        color = random.choice(color_pallette)
        numbr = random.choice(numbr_pallette)
        card = color + numbr
        card_list.append(card)
    return card_list

def deck_eval(deck_in):
    global val_list
    global summ
    print(summ)
    for item in deck_in:
        for item1 in item:
            item1_split = item1.split("-")
            if item1_split[1] == "B":
                val_list.append("10")
            elif item1_split[1] == "D":
                val_list.append("10")
            elif item1_split[1] == "K":
                val_list.append("10")
            elif item1_split[1] == "A":
                val_list.append("11")
            else:
                val_list.append(item1_split[1])
    for number in val_list:
        summ += int(number)
    if summ <= 21:
        return True
    else:
        return False
        

def selection_eval(choice):
    if choice == " ":
        return True
    elif choice == "QUIT" or "quit" or "Quit":
        leave = 1
    else:
        return False
    


leave = 0
player_deck = []
val_list = []
summ = 0

print("Welcome to Blackjack")
print("Enter SPACE to confirm. Enter anything to deny. Type QUIT to leave.")
while leave == 0:
    print()
    print("Call for cards?")
    choice = input()
    if selection_eval(choice):
        player_deck.append(card_gen(2)) #First two cards for player added to player_deck
        deck_eval(player_deck)
        print(player_deck)
    else:
        leave = 1
            
    while deck_eval(player_deck) == True: #As long as the evaluator detects the value of the cards to be below 21 it returns true.
        print()
        print("Hit?")
        choice = input()
        if selection_eval(choice):
            player_deck.append(card_gen(1))
            print(player_deck)
        else:
            print("hi")

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).