[Tutor] I need advice about which way to go.

Nathan Pinno falcon3166 at hotmail.com
Wed Aug 3 20:36:23 CEST 2005


Here is the code then:
#This is code for a blackjack game.
import random
cash = 0
new_cash = 100
cards = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
card_types = {"Diamond", "Heart", "Spade", "Club"}
bet = 0
playertotal = 0
comp_total = 0

def menu():
    print "1. Bet and play."
    print "2. Cash out and Exit"

def option():
    return int(raw_input("Menu choice: "))

def card_choice():
    return random.choice(range(1,14)

def types():
    return random.choice(range(1,5)

def player_cards():
    print a," of ",t1
    print b," of ",t2

print "Blackjack"
print "By Nathan Pinno"
while 1:
    menu()
    choice = option()
    if choice == 1:
        bet = int(raw_input("How much do you want to bet: ")
            while 1:
            if bet > new_cash:
                  print "Sorry, you don't have that much cash! Your total cash is: $",new_cash
            else:
                  break
        a,b = card_choice()
        t1,t2 = types()
        if t1 == 1:
            t1 = card_types[0]
        elif t1 == 2:
            t1 = cardtypes[1]
        elif t1 == 3:
            t1 = cardtypes[2]
        else:
            t1 = cardtypes[3]
        if a == 1:
            a = cards[0]
            playertotal = playertotal + 1
        elif a == 2:
            a = cards[1]
            playertotal = playertotal + 2
        
Now do you have an idea of what I'm pointing to?
  ----- Original Message ----- 
  From: Bob Gailer 
  To: Nathan Pinno ; Tutor mailing list 
  Sent: Wednesday, August 03, 2005 12:28 PM
  Subject: Re: [Tutor] I need advice about which way to go.


  At 11:12 AM 8/3/2005, Nathan Pinno wrote:

    Sorry about that, I thought it was clear that n = number randomly chosen. I 
    was thinking of if the number was a five, it would choose a card with a five 
    on it. I don't want to have to code stuff that I have to repeat again and 
    again.

  That's what classes, loops and functions are for.


    I'm not worrying about card types, I have that figured out separately.
    The two games are indeed separate, too much trouble to do them a 1 program 
    that can play both games.
    Maybe I should have shown my code and asked using the code as a visual 
    reference.

  Good idea. How about now?

  Bob Gailer
  phone 510 978 4454 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050803/98c3c1ee/attachment.htm


More information about the Tutor mailing list