To compare cards without the consideration of the suit | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

To compare cards without the consideration of the suit

I've created this deck and the game is able to get a card for the computer and another one for the player, but when I want to compare the values, the program considers that the suits are in order too. So, my question is How I manage to put an order to only consider the number and not the suit? import random numbers=[2,3,4,5,6,7,"Jack","Queen","King","Ace"] suits=["Hearts","Diamonds","Clubs","Spades"] deck=[] for i in suits: for j in numbers: card="{} of {}".format(j,i) deck.append(card) random.shuffle(deck) points_machine=0 points_human=0 card_machine=deck.pop() print ("The machine has", card_machine) card_human=deck.pop() print ("The player has", card_human) if card_machine>card_human: print ("The computer wins") points_machine=points_machine+1 print ("The computer has this punctuation:",points_machine)

17th May 2020, 8:29 PM
Conchi
Conchi - avatar
1 Answer
0
I haven't tested it fully (it's getting late now)...copy and paste it to playground or an IDE... import random numbers = dict(zip([x for x in range(2, 15)], [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"])) suits = ["Hearts", "Diamonds", "Clubs", "Spades"] deck = [] for i in suits: for j in numbers.keys(): card = (j, i) deck.append(card) random.shuffle(deck) points_machine = 0 points_human = 0 card_machine = deck.pop() print("The machine has", numbers[card_machine[0]], card_machine[1]) card_human = deck.pop() print("The player has", numbers[card_human[0]], card_human[1]) if card_machine[0] > card_human[0]: print("The computer wins") points_machine=points_machine+1 print("The computer has this punctuation:", points_machine)
17th May 2020, 10:51 PM
rodwynnejones
rodwynnejones - avatar