Can anyone tell me how to write a program that displays all of the cards from a deck of playing cards? i set up two tuples, one with the
ranks and the other with the suits. I cant figure out how to make the Ace of spades - King of spades......combining parts of my tuples together.

[rank = (("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")) suit = (("c", "h", "s", "d")) card = ()]

Thanks

Recommended Answers

All 2 Replies

Two loops will do, or you can use a list comprehension:

rank = ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
suit = ("c", "h", "s", "d")

card = []
for r in rank:
    for s in suit:
        card.append(r+s)

card = tuple(card)
print(card)

"""
my result made pretty -->
('Ac', 'Ah', 'As', 'Ad', '2c', '2h', '2s', '2d', '3c', '3h', '3s', 
'3d', '4c', '4h', '4s', '4d', '5c', '5h', '5s', '5d', '6c', '6h', 
'6s', '6d', '7c', '7h', '7s', '7d', '8c', '8h', '8s', '8d', '9c', 
'9h', '9s', '9d', '10c', '10h', '10s', '10d', 'Jc', 'Jh', 'Js', 
'Jd', 'Qc', 'Qh', 'Qs', 'Qd', 'Kc', 'Kh', 'Ks', 'Kd')
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.