Python Forum
Blackjack total from string HW
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blackjack total from string HW
#3
(Apr-27-2017, 10:06 AM)ichistarr Wrote: At the moment the hand displays as [AH, 3S] but i'm required to display it in text format along with the total, eg: (Player Hand Total is 4/14 with Ace of Hearts and 3 of Spades)
It's not an so easy task as you are given a list(that you can not change) as shall display that as output.
Can give some hint.
Could map the list values onto to a dictionary.
Eg.
>>> cards = {'3S': {'3 of Spades': 3}, 'AH': {'Ace of Hearts': 11}}
>>> my_hand = ['AH', '3S']
>>> cards_info = []
>>> for value in my_hand:
...     if value in cards:
...         cards_info.append(cards[value])
... 
>>> cards_info
[{'Ace of Hearts': 11}, {'3 of Spades': 3}]
So now have list with text and values of my_hand.
>>> # Display
>>> print('{} - {}'.format(''.join(cards_info[0]), ''.join(cards_info[1])))
Ace of Hearts - 3 of Spades

>>> # Calculate
>>> def clac(cards_info):     
...     for item in cards_info:
...         for card in item:
...             yield item[card]
            
>>> total = sum(dislay(cards_info))
>>> print('Card value {}/{}'.format(total-10, total))
Card value 4/14
@idontreallywolf look into string formatting,stuff like this is not nice +str(num)+"/"+str(maxnum)+.
Reply


Messages In This Thread
Blackjack total from string HW - by ichistarr - Apr-27-2017, 10:06 AM
RE: Blackjack total from string HW - by snippsat - Apr-27-2017, 03:17 PM
RE: Blackjack total from string HW - by snippsat - Apr-27-2017, 05:12 PM
RE: Blackjack total from string HW - by nilamo - Apr-27-2017, 05:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Blackjack unionjackandsally 4 2,715 Apr-27-2020, 08:39 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020