please name this cards.py. You may use the following code in your program: import random SUITS = "♠ ♡ ♢ ♣".split() RANKS = "2 3 4 5 6 7 8 9 10 J Q K A".split() def create_deck(shuffle=False): """Create a new deck of 52 cards""" deck = [(s, r) for r in RANKS for s in SUITS] if shuffle: random.shuffle(deck)
please name this cards.py.
You may use the following code in your program:
import random
SUITS = "♠ ♡ ♢ ♣".split()
RANKS = "2 3 4 5 6 7 8 9 10 J Q K A".split()
def create_deck(shuffle=False):
"""Create a new deck of 52 cards"""
deck = [(s, r) for r in RANKS for s in SUITS]
if shuffle:
random.shuffle(deck)
return deck
This code creates a random deck of cards (each card is a tuple consisting of a rank and
suit). You are to ask the user how many 5-card hands to play and will keep track of the
following poker hands. You will need to reshuffle the deck as many times as necessary to get the required number of hands.
An example run of the program is as follows.
Enter the number of hands to deal: 10000
Hand % of Hands Hands of Type
2 of a kind 41.290% 4129
3 of a kind 1.970% 197
4 of a kind 0.010% 1
2 pair 4.860% 486
Full house 0.150% 15
Flush 0.220% 22
If you deal enough hands the percentage for each hand should approach the values shown in the table on this page.
Since this is a harder assignment, I would suggest you start with determining if a hand is a flush (all cards of the same suit). I will give more credit for printing the percentage of more of the hands. You can also add the results for straights, straight flushes and royal flushes if you want, which will earn you extra credit points. I am also giving extra credit for using list comprehensions in the solution.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps