#!/usr/bin/Python # My Blackjack Game - Simple version # import statements from __future__ import print_function #from IPython.display import clear_output import random import os #global variables suits = ('Hearts','Diamonds','Spades','Clubs') ranks = ('Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King','Ace') values = {'Two':2,'Three':3,'Four':4,'Five':5,'Six':6,'Seven':7,'Eight':8,'Nine':9,'Ten':10,'Jack':10,'Queen':10,'King':10,'Ace':11} playing = True # card classs class Card: def __init__(self, suit, rank): self.suit=suit self.rank=rank def __str__(self): return ("%s of %s" %(self.rank, self.suit)) # deck class class Deck: def __init__(self): self.deck=[] for suit in suits: for rank in ranks: self.deck.append(Card(suit,rank)) def __str__(self): deck_comp = '' for card in self.deck: deck_comp += "\n " + card.__str__() return deck_comp def shuffle(self): random.shuffle(self.deck) def deal(self): single_card = self.deck.pop() return single_card # Hand Class class Hand: def __init__(self): self.cards=[] self.value=0 self.aces=0 def addCard(self, card): self.cards.append(card) self.value += values[card.rank] def adjustForAce(self): while self.value > 21 and self.aces: self.value -= 10 self.aces -= 1 # Chips Class class Chips: def __init__(self): self.total=150 self.bet=0 def winBet(self): self.total += self.bet def looseBet(self): self.total -= self.bet # utility functions def startbet(chips): while True: try: chips.bet = int(input("How many chips do you want to bet?")) except ValueError: print("Sorry!!!!, Please enter a number for bet.") else: if(chips.bet> chips.total): print("Sorry!!!, Please enter the bet value less than your total.") else: break; def hit(deck, hand): hand.addCard(deck.deal()) hand.adjustForAce() def hitorStand(deck,hand): global playing while True: x = int(input("Would you like to Hit or Stand? Enter '0' for hit, '1' for stand ")) if x == 0: hit(deck,hand) elif x == 1: print("Player stands. Dealer is playing.") playing = False else: print("Sorry, please try again.") continue break def ShowCardsNow(player, dealer): print("\nDealer's Hand:") print("