This script allows the user to randomly draw a card from a deck of cards. Once a card is chosen, it is removed from the deck and you can continue drawing cards until it runs out.
import random # Create a standard deck of 52 playing cards suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] deck = [] # Manually populate the deck instead of using a list comprehension for suit in suits: for rank in ranks: deck.append(rank + " of " + suit) def draw_card(): if deck: card = random.choice(deck) # Select a random card deck.remove(card) # Remove the selected card from the deck return card else: return None # Return None when the deck is empty while deck: print("Press Enter to draw a card...") # Prompting message print("Input exit to quit simulator") _ = input() # Waits for user input (NumWorks may require adjustments) if _.lower() == 'exit': print("Exiting the script. Goodbye!") break drawn_card = draw_card() if drawn_card: print("You drew:", drawn_card) else: print("The deck is empty! No more cards to draw.") break print("Game over! Thanks for playing.")