Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:24:24+00:00 2026-06-09T18:24:24+00:00

I’m learning python (with VBA background) by building a black-jack game (Yes, I’ve asked

  • 0

I’m learning python (with VBA background) by building a black-jack game (Yes, I’ve asked a bunch of questions using blackjack as an example).

Here’s my code:

import random

class DECK():
    def load_deck(self):
        suite = ('Spades', 'Hearts', 'Diamonds', 'Clubs')
        rank = ('2', '3', '4', '5', '6', '7', '8', '9', '10', "Jack", "Queen", "King", "Ace")
        full_deck = {}
        i = 0
        for s in suite:
            for r in rank:
                full_deck[i] = "%s of %s" % (r, s)
                i += 1
        return full_deck

    def pick_item(self, deck):   
        card_key = random.choice(deck.keys())  
        new_card = deck[card_key] 
        del deck[card_key]  
        return (deck, new_card)

    def missing_card(self, deck):
        temp_deck = DECK()
        print temp_deck

d1 = DECK()

deck1 = d1.load_deck()

deck1, card1 = d1.pick_item(deck1)

print card1

d1.missing_card(d1)

Here’s what I get in the terminal (file namehand_c.py):

$ python hand_c.py
Ace of Clubs
<__main__.DECK instance at 0x10bb0d248>
$ 

Why does one function work pick_item, but not the other missing_card?

Per the first answer, I changed the function definition to:

    def missing_card(self, deck):
    deckC1 = DECK()
    temp_deck = deckC1.load_deck
    print temp_deck

But now I get the following from the terminal:

$ python hand_c.py
Jack of Diamonds
<bound method DECK.load_deck of <__main__.DECK instance at 0x10500e248>>
$ 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:24:25+00:00Added an answer on June 9, 2026 at 6:24 pm

    I modified your program to work. I introduced a constructor and changed the representation of your deck to a list instead of a dictionary, and made it to a instance variable that belongs to the deck you create in the line d1 = DECK(). Every method in your class now has access to your deck, without revealing your internal representation of the deck to the world and you only have to work with the one DECK object.

    import random
    
    class DECK():
        def __init__(self):
            suite = ('Spades', 'Hearts', 'Diamonds', 'Clubs')
            rank = ('2', '3', '4', '5', '6', '7', '8', '9', '10', "Jack", "Queen", "King", "Ace")
            self.full_deck = []
            for s in suite:
                for r in rank:
                    self.full_deck.append("%s of %s" % (r, s))
    
        def pick_item(self):
            card_key = random.randint(0, len(self.full_deck)-1)  
            new_card = self.full_deck[card_key] 
            del self.full_deck[card_key]  
            return new_card
    
        def missing_card(self):
            print self.full_deck
    
    d1 = DECK()
    card1 = d1.pick_item()
    
    print card1
    
    d1.missing_card()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.