#declaring variables

import random

import sys

import time

while 1 :

random . seed ( )

#Player makes bet

money = 500

print ( """

____ _ _ _ _

| _ \| | | | | | | |

| |_) | | __ _ ___| | __ | | __ _ ___| | __

| _ <| |/ _` |/ __| |/ / | |/ _` |/ __| |/ /

| |_) | | (_| | (__| < |__| | (_| | (__| <

|____/|_| \_ _,_| \_ __|_| \_ \_ ___/ \_ _,_| \_ __|_| \_ \

""" )

thisthing = 0

while money > 0 and thisthing != 1 :

cards = [ [ 2 , '2 of clubs' ] , [ 3 , '3 of clubs' ] , [ 4 , '4 of clubs' ] , [ 5 , '5 of clubs' ] , [ 6 , '6 of clubs' ] , [ 7 , '7 of clubs' ] , [ 8 , '8 of clubs' ] , [ 9 , '9 of clubs' ] , [ 10 , '10 of clubs' ] , [ 2 , '2 of spades' ] , [ 3 , '3 of spades' ] , [ 4 , '4 of spades' ] , [ 5 , '5 of spades' ] , [ 6 , '6 of spades' ] , [ 7 , '7 of spades' ] , [ 8 , '8 of spades' ] , [ 9 , '9 of spades' ] , [ 10 , '10 of spades' ] , [ 2 , '2 of hearts' ] , [ 3 , '3 of hearts' ] , [ 4 , '4 of hearts' ] , [ 5 , '5 of hearts' ] , [ 6 , '6 of hearts' ] , [ 7 , '7 of hearts' ] , [ 8 , '8 of hearts' ] , [ 9 , '9 of hearts' ] , [ 10 , '10 of hearts' ] , [ 2 , '2 of diamonds' ] , [ 3 , '3 of diamonds' ] , [ 4 , '4 of diamonds' ] , [ 5 , '5 of diamonds' ] , [ 6 , '6 of diamonds' ] , [ 7 , '7 of diamonds' ] , [ 8 , '8 of diamonds' ] , [ 9 , '9 of diamonds' ] , [ 10 , '10 of diamonds' ] , [ 11 , 'ace of clubs' ] , [ 11 , 'ace of spades' ] , [ 11 , 'ace of hearts' ] , [ 11 , 'ace of diamonds' ] , [ 10 , 'queen of clubs' ] , [ 10 , 'queen of spades' ] , [ 10 , 'queen of hearts' ] , [ 10 , 'queen of diamonds' ] , [ 10 , 'king of clubs' ] , [ 10 , 'king of spades' ] , [ 10 , 'king of hearts' ] , [ 10 , 'king of diamonds' ] , [ 10 , 'jack of clubs' ] , [ 10 , 'jack of spades' ] , [ 10 , 'jack of hearts' ] , [ 10 , 'jack of diamonds' ] ]

start1 = random . choice ( cards )

x = start1 [ 0 ]

cards. remove ( start1 )

start2 = random . choice ( cards )

x+ = start2 [ 0 ]

cards. remove ( start2 )

dealer1 = random . choice ( cards )

z = dealer1 [ 0 ]

y = dealer1 [ 0 ]

cards. remove ( dealer1 )

dealer2 = random . choice ( cards )

z+ = dealer2 [ 0 ]

cards. remove ( dealer2 )

bet = float ( input ( "What's your bet? Max is " + str ( money ) + "

" ) )

while bet > money or bet <= 0 :

print ( "

You can't bet more than you have! Bet again!" )

bet = float ( input ( "What's your bet? Max is " + str ( money ) + "

" ) )

betog = float ( bet )

print ( "debug line 39" )

if start1 [ 0 ] +start2 [ 0 ] == 22 :

start1 [ 0 ] = 1

if dealer1 [ 0 ] +dealer2 [ 0 ] == 22 :

dealer1 [ 0 ] = 1

z = dealer1 [ 0 ] +dealer2 [ 0 ]

x = start1 [ 0 ] +start2 [ 0 ]

print ( "debug line 46" )

print ( "You have been dealt " +start1 [ 1 ] + " and " +start2 [ 1 ] + "

Dealer has dealt " +dealer1 [ 1 ] + " and a face-down card" )

if x == 21 :

print ( "That's blackjack! You win $" + str ( bet* 1.5 ) + "!" )

money+ = bet* 1.5

play_again = float ( input ( "

Would you like to play again?

1. Yes

2. No (and go home with your winnings of " + str ( money ) + ")

" ) )

if play_again == 2 :

sys . exit ( )

else :

thisthing = 1

elif x == 21 == z:

print ( "You both had 21! It's a tie!" )

sys . exit ( )

else :

print ( "Current point total is " + str ( x ) + " for you and " + str ( y ) + " for the dealer" )

if thisthing != 1 :

print ( "debug line 62" )

choice = float ( input ( "

1. Hit

2. Double-Down

3. Stand

" ) )

print ( "debug line 64" )

if choice == 1 :

print ( "debug line 66" )

while choice != "2" and thisthing != 1 :

print ( "debug line 68" )

draw1 = random . choice ( cards )

x+ = draw1 [ 0 ]

if x > 21 :

print ( "You went over 21 and lost!" )

money- = betog

thisthing = 1

else :

cards. remove ( draw1 )

print ( "You have been dealt " +draw1 [ 1 ] + "

Current point total is " + str ( x ) + "

Hit again?

1. Yes

2. No (Stand)

" )

choice = input ( )

if choice == 2 and thisthing != 1 :

bet = bet* 2

draw1 = random . choice ( cards )

x+ = draw1 [ 0 ]

if x > 21 :

print ( "You went over 21 and lost!" )

thisthing = 1

cards. remove ( draw1 )

print ( "You have been dealt " +draw1 [ 1 ] + "

Current point total is " + str ( x ) + "

Bet is now " + str ( bet ) )

if thisthing != 1 :

time . sleep ( 1 )

print ( "

Time for the dealer's turn" )

time . sleep ( 1 )

print ( "The dealer's other card was a(n) " +dealer2 [ 1 ] + ", bringing their score to " + str ( z ) )

if z >= 17 and thisthing != 1 :

if z > x:

print ( "The dealer wins! You lost your " + str ( bet ) + " dollar investment" )

money- = betog

thisthing = 1

elif z == x:

print ( "You tie! You get to keep your original " + str ( betog ) + " dollars." )

else :

print ( "You win! You get to keep your earnings of " + str ( bet ) + " dollars!" )

money+ = betog

thisthing = 1

while ( z < 17 ) and thisthing != 1 :

dealerEnd = random . choice ( cards )

z+ = dealerEnd [ 0 ]

time . sleep ( 1 )

print ( "The dealer's score is currently " + str ( z ) + " after drawing a " +dealerEnd [ 1 ] )

if z >= 21 :

print ( "The dealer went over 21 and you win! You get to keep your earnings of " + str ( bet ) + " dollars!" )

money+ = betog

thisthing = 1

if z >= 17 :

break

cards. remove ( dealerEnd )

if z >= 17 and thisthing != 1 :

if z > x:

print ( "The dealer wins! You lost your " + str ( bet ) + " dollar investment" )

money- = betog

thisthing = 1

elif z == x:

print ( "You tie! You get to keep your original " + str ( betog ) + " dollars." )

thisthing = 1

else :

print ( "You win! You get to keep your earnings of " + str ( bet ) + " dollars!" )

thisthing = 1

if thisthing == 1 :

play_again = float ( input ( "

Would you like to play again?

1. Yes

2. No

" ) )

if play_again == 2 :

sys . exit ( )

print ( "You can't play without any money!" )