I need you to give me 2 different letters

2

I'm trying to make a poker game to play. The problem is that at the time of telling him that he is giving me two cards from the deck, he gives me only one card twice.

For example, you give me Q of heart and Q of heart or 5 of diamonds and 5 of diamonds. The problem is that it is the same letter. I need two different decks from the deck. I show you what I did next:

palos = ["h","d","c","s"]
rangos = ["2","3","4","5","6","7","8","9","10","J","Q","K","A"]

Mazo = []

for palo in palos:

    for rango in rangos:

       Mazo.append(rango + palo)
Mazo=set(list(Mazo))

import random

while len(Mazo)>1:
  Mazo.remove(random.choice(list(Mazo)))
  #print(Mazo)    

#print(Mazo)
print("\n")

for Carta in Mazo:

    Jugador1 = Carta
    print("\n")
    Jugador2 = Carta
    print(Jugador1)
    print(Jugador2)
    
asked by Godprogrammer 29.09.2017 в 06:14
source

1 answer

2

That's because you're deleting all the cards, except one in this part:

while len(Mazo)>1:
  Mazo.remove(random.choice(list(Mazo)))

And then they're printing that single letter twice. What I would do is take a card, assign it to a player, print it and then delete it. This would make the for. The program would look like this:

palos = ["h","d","c","s"]
rangos = ["2","3","4","5","6","7","8","9","10","J","Q","K","A"]

Mazo = []

for palo in palos:

    for rango in rangos:

       Mazo.append(rango + palo)
Mazo=set(list(Mazo))

import random

while len(Mazo) > 1:
    jugador1 = random.choice(list(Mazo))
    Mazo.remove(jugador1)
    jugador2 = random.choice(list(Mazo))
    Mazo.remove(jugador2)
    print("Jugador 1: ", jugador1)
    print("Jugador 2: ", jugador2)

If you want all the cards to be saved, then each player should have a lista of cards.

If you only want two cards, you can eliminate the while and leave only what is inside. You can also put a larger number in the while (such as 40 or 50, to distribute fewer letters): while len (Mazo) > 48

    
answered by 29.09.2017 / 07:40
source