Im a novice in programming and i have these codes for a blackjack game.but it failed -
from random import *
-
from math import *
-
-
#GLOBAL VARIABLES
-
-
cards = range(0,52)
-
-
def randRange(in_lower,in_upper):
-
""" generates a random number between in_lower and in_upper"""
-
temp_range = in_upper - in_lower
-
return int(round((temp_range)*random() + (in_lower)))
-
-
-
def popRandArray(in_list):
-
return in_list.pop(randRange(0,len(in_list)-1))
-
-
def realDealCard():
-
-
global cards
-
if len(cards)==0:
-
print "new deck"
-
cards = range(0,52)
-
return popRandArray(cards)
-
-
-
def cardAsString(in_card):
-
-
value = ["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
-
suit = ["hearts","diamonds","spades","clubs"]
-
return value[in_card%13]+ " of " + suit[in_card/13]
-
-
-
-
def cardScore(in_card):
-
-
score = in_card%13+1
-
if score > 10:
-
score = 10
-
return score
-
from random import *
-
from math import *
-
-
#GLOBAL VARIABLES
-
-
cards = range(0,52)
-
-
def randRange(lower,upper):
-
"""return a value in the range in_lower to in_upper
-
inclusive
-
"""
-
temp_range = upper - lower
-
return int(round((temp_range+0.5)*random() + (lower - 0.5)))
-
-
def dealCard():
-
"""simulate a deal from a hand of cards
-
"""
-
return randRange(0,51)
-
-
def randArray(in_list):
-
return in_list[randRange(0,len(in_list)-1)]
-
-
def popRandArray(in_list):
-
""" return a random value from an array with no replacement
-
"""
-
return in_list.pop(randRange(0,len(in_list)-1))
-
-
def dealCardTuple():
-
"""return a tuple with a random card assigned
-
"""
-
return int(randRange(0,12)),int(randRange(0,3))
-
-
def cardTupleAsString(in_tuple):
-
"""turn a deal from a hand of cards as a tuple into a string
-
"""
-
temp_value,temp_suite = in_tuple
-
value = ["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
-
suite = ["hearts","diamonds","spades","clubs"]
-
return value[temp_value]+ " of " + suite[temp_suite]
-
-
def cardAsString(in_card):
-
"""turn a deal from a hand of cards as a tuple into a string
-
"""
-
value = ["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
-
suit = ["hearts","diamonds","spades","clubs"]
-
return value[in_card%13]+ " of " + suit[in_card/13]
-
-
def realDealCard():
-
"""performs a non replacement randomised lookup
-
"""
-
global cards
-
#check to see if the array still has a card in it
-
if len(cards)==0:
-
print "new deck"
-
cards = range(0,52)
-
return popRandArray(cards)
-
-
def testCards():
-
"""tests the distribution of card when dealing a mulitple
-
number of hands"""
-
hands=int(raw_input('how many hands do you want to play?:'))
-
histo = 52 * [0]
-
for i in range(1,hands*52+1):
-
n = realDealCard()
-
histo[n] = histo[n] + 1
-
for i,v in enumerate(histo):
-
print cardAsString(i) + " " + str(v)
-
#print dealCard()
-
def cardScore(in_card):
-
"""converts a card into a numerical score"""
-
score = in_card%13+1
-
if score > 10:
-
score = 10
-
return score
-
-
def bestScore(in_array):
-
"""take an array and produces the best possible score without
-
going bust"""
-
#what is total score with ace = 1
-
score_array = map(cardScore,in_array)
-
print score_array
-
#what's the difference between 21 and the score
-
#if it's >= 10 then add on 10
-
out_score = sum(score_array)
-
if 1 in score_array:
-
if 21-out_score >=10:
-
return out_score+10
-
else:
-
return out_score
-
else:
-
return out_score
-
-
def exampleCards():
-
for i in range(100):
-
player_hand = [realDealCard() for i in range(3)]
-
print player_hand
-
score = bestScore(player_hand)
-
if score>21:
-
print "bust"
-
else:
-
print score
-
-
exampleCards()
1 1645 bvdet 2,851
Expert Mod 2GB
nytgangsta101,
I renamed the thread to a more appropriate title. I also added code tags for you. Please see posting guidelines here.
If you would post the actual error you received including the traceback, it would help us pinpoint the problem.
BV - Moderator
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Charlie Cosse |
last post by:
Asymptopia BlackJack is written in Python and uses PyGame for
multimedia.
Version 1.2 contains both Windows and Linux install scripts.
Asymptopia BlackJack is a full-featured casino-style...
|
by: slyphiad |
last post by:
Here's the problem that i got...
I'm trying to create a blackjack game. Here, I'm trying to create 2
blackjack games. A game with bet and without bet. So basically what i
did, was create 2...
|
by: CapMaster |
last post by:
I've found some programs of how to create a standard game of blackjack on C++. But how would you do it using structs? Here is my assignment:
Problem Statement: The purpose of this project is to...
|
by: blinkrebel |
last post by:
Hello
I need some help implementing the game of blackjack using the xturtle package.
the instructions can be found at
http://katie.luther.edu/moodle/file.php/2387/BlackJack.pdf
and .gif's...
|
by: EXotiX |
last post by:
hey im new to vb6 and I am making a blackjack game but can not randomize the array correctly. Could you help please
Option Explicit
Const NumItems As Integer = 53
Public Sub RandomizeCards()...
|
by: devilinthebox |
last post by:
I am not really familar with Java and I need help with creating this simple Blackjack program.
Here is a layout of how the program should output:
If the computer has more than 16 it wins,...
|
by: devilinthebox |
last post by:
I'm fairly new to java and need help with adding letters (J, Q, K, A) into the program and adding values for each. Thanks.
// February 8, 2008
// The "BlackJack" class.
import java.awt.*;...
|
by: Z E R O |
last post by:
I'm in a really fast pace training program and we are covering a lot of material in a relatively short period of time. I've really not had much trouble up until this problem. I had to do one other...
|
by: imran akhtar |
last post by:
i have a balckjack code, which does not seem to run, in python, it comes up with syntax error, i have try sortng it out. does not seem to work. below is my code, if anyone can work out wht wrong...
|
by: imran akhtar |
last post by:
hi, i am making black jack code, but i am stuck, i have made start, but for reason gettin errors, which i dont seem be able to fix, below is my code wht i started.
import random
deck = *4...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |