I'm currently trying to make a Blackjack game, but I get the error:
AttributeError: 'builtin_function_or_method' object has no attribute 'choice'
I have tried to split the codes into smaller parts, but I can't figure out what's wrong. I would greatly appreciate if someone would help me!
These are my codes:
import random
from pylab import *
chips=0
bet=0
yourCards=0
kortstokk=[1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13]
p_firstCard=0
d_firstCard=0
p_secondCard=0
d_secondCard=0
dealerCards=0
END=False
def beginPlayer():
global yourCards
p_firstCard=random.choice(kortstokk)
kortstokk.remove(p_firstCard)
p_secondCard=random.choice(kortstokk)
kortstokk.remove(p_secondCard)
yourCards=p_firstCard+p_secondCard
return yourCards
#end beginPlayer
def beginDealer():
global dealerCards
d_firstCard=random.choice(kortstokk)
kortstokk.remove(d_firstCard)
d_secondCard=random.choice(kortstokk)
kortstokk.remove(d_secondCard)
dealerCards=d_firstCard+d_secondCard
return dealerCards
#end beginDealer
def playerHit():
global yourCards
p_hit=0
p_hit=random.choice(kortstokk)
kortstokk.remove(p_hit)
yourCards=yourCards+p_hit
return yourCards
#end p_hit
def playerWon():
global bet
global chips
chips=0
print("Congratulation, you won this hand and will recive the twice your bet.")
chips=chips+(2*bet)
#end playerWon
def dealerWon():
print("You lost this round. Better luck next round.")
global bet
bet=0
#end dealerWon
def bothWin():
global chips
global bet
print("You had equal cards.")
print("You will recive your original bet again.")
chips=chips+bet
bet=0
#end bothWin
def showWin():
if dealerCards>21:
playerWon()
if yourCards>21:
dealerWon()
if 21>=yourCards and yourCards>dealerCards:
playerWon()
if 21>=dealerCards and dealerCards>yourCards:
dealerWon()
if yourCards==dealerCards:
bothWin()
#end showDealer
while not END:
bet=input("Place your bet > ")
bet=int(bet)
beginPlayer()
beginDealer()
print("Your card amount is : ",yourCards)
print("The dealer's first card is : ",d_firstCard)
hit1=input("Would you like to hit or stand?(h/s) > ")
if hit1=="h":
playerHit()
hit2=input("Would you like to hit or stand?(h/s) > ")
if hit2=="h":
playerHit()
hit3=input("Would you like to hit or stand?(h/s) > ")
if hit3=="h":
playerHit()
hit4=input("Would you like to hit or stand?(h/s) > ")
if hit4=="h":
playerHit()
hit5=input("Would you like to hit or stand?(h/s) > ")
if hit5=="h":
playerHit()
if hit5=="s":
showWin()
else:
print("Ukjent kommando...")
#end if
if hit4=="s":
showWin()
else:
print("Ukjent kommando...")
#end if
if hit3=="s":
showWin()
else:
print("Ukjent kommando...")
#end if
if hit2=="s":
showWin()
else:
print("Ukjent kommando...")
#end if
if hit1=="s":
showWin()
else:
print("Ukjent kommando...")
playAgain=input("Do you want to play again? (y/n) > ")
if playAgain=="n":
END
if playAgain=="y":
not END
#end if
#end while
Aucun commentaire:
Enregistrer un commentaire