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 835593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:50:54+00:00 2026-05-15T04:50:54+00:00

def showCards(): #SUM sum = playerCards[0] + playerCards[1] #Print cards print Player’s Hand: +

  • 0
def showCards():
    #SUM
    sum = playerCards[0] + playerCards[1]
    #Print cards
    print "Player's Hand: " + str(playerCards) + " : " + "sum"
    print "Dealer's Hand: " + str(compCards[0]) + " : " + "sum"


    compCards = [Deal(),Deal()]    
    playerCards = [Deal(),Deal()]

How can i add up the integer element of a list containing to values? under #SUM error is can combine lists like ints…

  • 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-05-15T04:50:55+00:00Added an answer on May 15, 2026 at 4:50 am

    Aside from the comments mentioned above, sum is actually a built in function in Python that does just what you seem to be looking for – so don’t overwrite it and use it as an identifier name! Instead use it.

    Also there’s a style guide that all Python programmers are meant to follow – it’s what helps to further distinguish Python code from the inscrutable sludge often encountered in code written in other languages such as say Perl or PHP. There’s a higher standard in Python and you’re not meeting it. Style

    So here’s a rewrite of your code along with some guesses to fill in the missing parts.

    from random import randint
    
    CARD_FACES = {1: "Ace", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 
                  9: "9", 10: "10", 11: "Jack", 12: "Queen", 13: "King"}
    
    def deal():
        """Deal a card - returns a value indicating a card with the Ace
           represented by 1 and the Jack, Queen and King by 11, 12, 13
           respectively.
        """
        return randint(1, 13)
    
    def _get_hand_value(cards):
        """Get the value of a hand based on the rules for Black Jack."""
        val = 0
        for card in cards:
            if 1 < card <= 10:
                val += card # 2 thru 10 are worth their face values
            elif card > 10:
                val += 10 # Jack, Queen and King are worth 10
    
        # Deal with the Ace if present.  Worth 11 if total remains 21 or lower
        # otherwise it's worth 1.
        if 1 in cards and val + 11 <= 21:
            return val + 11
        elif 1 in cards:
            return val + 1
        else:
            return val    
    
    def show_hand(name, cards):
        """Print a message showing the contents and value of a hand."""
        faces = [CARD_FACES[card] for card in cards]
        val = _get_hand_value(cards)
    
        if val == 21:
            note = "BLACK JACK!"
        else:
            note = ""
    
        print "%s's hand: %s, %s : %s %s" % (name, faces[0], faces[1], val, note)
    
    
    # Deal 2 cards to both the dealer and a player and show their hands
    for name in ("Dealer", "Player"):
        cards = (deal(), deal())
        show_hand(name, cards)
    

    Well ok so I got carried away and actually wrote the whole thing. As another poster wrote sum(list_of_values) is the way to go but actually is too simplistic for the Black Jack rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def myFunc( str ): print str=, str if str == None: print str is
def a(): w='www' a.a='aaa' print a.__dict__ a.__dict__={'1':'111','2':'222'} print a.1#error print a['1']#error how can i
def display_hand(hand): for letter in hand.keys(): for j in range(hand[letter]): print letter, Will return
def initialize(apps, catch=404) @apps = []; @has_app = {} apps.each { |app| add app
def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in
def myFunc(arg1, arg2): print This is a test with + arg1 + and +
def display_home(request): from datetime import * now=datetime.today() print 'Month is %s'%now.month events=Event.objects.filter(e_date__year=datetime.today().year).filter(e_date__month=datetime.today().month,e_status=1).values('e_name','e_date') return render_to_response("SecureVirtualElection/home.html",{'events':
def ask(): global name, loca print What's your name? name = raw_input('> ') print
def applejuice(q): print THE FUNCTION NAME! It should result in applejuice as a string.
def exec_command(self, command, bufsize=-1): #print Executing Command: +command chan = self._transport.open_session() chan.exec_command(command) stdin =

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.