0

I have written a program that randomly generates a hand consisting of two cards. I want it to generate hands until certain combinations occur eg. a pair or a premium hand such as AK, AQ or KQ.

I have already covered the possibility of a pair being drawn (this was fairly straightforward). I also want it to stop the while loop when suited connectors occur; eg. 98 suited or 65 suited. How could I assign a value to each card in order to do this?

def generateHand():
    pair = False
while playables == False:
    first_rank =     random.choice(('A','2','3','4','5','6','7','8','9','T','J','Q','K'))
    print(first_rank)
    first_suit = random.choice(('d','c','h','s'))

    second_rank =      random.choice(('A','2','3','4','5','6','7','8','9','T','J','Q','K'))
    print(second_rank)
    second_suit = random.choice(('d','c','h','s'))

    isSuited = 'o'
    if first_suit == second_suit:
        isSuited = 's'
    print isSuited
    print(' ')

    if first_rank == second_rank:
        playable = True
  • 2
    Hi there, welcome to Stack Overflow! Please [edit] your question to make sure that the code is properly formatted :) – grooveplex Oct 16 '19 at 17:25
  • If you want a suited pair of cards, don't pick the second suit at random; just use the first suit for both cards. In general, you don't want to pick a *completely* random second card; you want to make your choices based on the first card chosen. – chepner Oct 16 '19 at 17:27
  • 2
    Don't represent cards as strings. Represent them as numbers that are easy to compare, and convert to/from strings only for I/O. – Lee Daniel Crocker Oct 17 '19 at 16:09

0 Answers0