Apr-27-2017, 03:17 PM
(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)+
.