So I got bored and made a blackjack game. This is probably be the last thing I code in python before I move to C#!!!(so excited to learn it)
The game() function is the main fuction all the rest are pretty self explanatory if you understand blackjack. My issue is that when you deal the cards and it ask if you want to hit it gives me an error no matter the input.
#Black Jack
import random
# Main function
def game():
computerHand = deal()
playerHand = deal()
print "Welcome to Blackjack!"
print "---START GAME---"
#begin/deal the card
start=raw_input("Deal cards? [Y/N]")
global playerHand
global computerHand
if start=="Y" or "y":
print "Your cards are: "+str(playerHand)
print "Dealer's Cards are:"+str(computerHand)
hit=raw_input("Do you want to hit? [Y/N] ")
if hit=="Y" or "y":
hit()
#check it hit busted player
bust()
print str(playerHand)
else:
print "You stand with"+str(playerHand)
else:
print "Fine then, Don't play..."
#Deal player/comp new hand
def deal():
random1 = random.randint(1,14)
random2 = random.randint(1,14)
#first card/Converts face card to accual value
if random1 == 11:
random1 = "J"
if random1 == 12:
random1 = "Q"
if random1 == 13:
random1 = "K"
if random1 == 14:
random1 = "A"
#second card
if random2 == 11:
random2 = "J"
if random2 == 12:
random2 = "Q"
if random2 == 13:
random2 = "K"
if random2 == 14:
random2 = "A"
hand = [random1,random2]
return hand
def hit():
newCard = random.randint(1,14)
if newCard == 11:
newCard = "J"
if newCard == 12:
newCard = "Q"
if newCard == 13:
newCard = "K"
if newCard == 14:
newCard = "A"
global playerHand
playerHand.append(str(newCard))
def bust():
"""Detect if player hitting put him over 21"""
if playerHand>21:
print "Your over 21 your BUSTED!"
elif playerHand==21:
print "You got blackjack! :]"
elif playerHand<21:
#PLAYER is good and not busted
pass
def dealer():
"""Defines dealers stragety"""
global computerHand
if computerHand>=15:
pass
elif computerHand<15:
hit()
#This is the console input that results in error.
Welcome to Blackjack!
---START GAME---
Deal cards? [Y/N]y
Your cards are: [4, 7]
Dealer's Cards are:['K', 3]
Do you want to hit? [Y/N] y
Traceback (most recent call last):
File "/private/var/folders/3W/3Wn7b1HVGVG3oJSMntLupk+++TI/Cleanup At Startup/BlackJack-295612489.335.py", line 113, in <module>
game()
File "/private/var/folders/3W/3Wn7b1HVGVG3oJSMntLupk+++TI/Cleanup At Startup/BlackJack-295612489.335.py", line 21, in game
hit()
TypeError: 'str' object is not callable
logout