Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.4 kB
1
Indexable
Never
import random

def create_deck():
  """ Takes no parameter
  Creates and returns a 2D-list """
  
  # an intially empty deck
  deck = []
  suits = ["RED", "BLK"]
  values = []
  
  # creates a list of all face values
  for x in range(2,10):
    values.append(x)
  
  # creates cards [s,f] and inserting them to the deck
  for s in suits:
    for f in values:
      deck.append([s, f])
  return deck

def shuffle(deck):
    """Takes a 2-D list
        Returns a shuffled 2-D list"""
    
    # copies the deck to a new list, so the original deck remains same    
    shdeck = deck[:]
    random.shuffle(shdeck)
    return shdeck


def deal(deck):
  board = []
  for row in range(3):
    board.append([])
    for col in range(3):
      board[row].append(deck.pop(0))

  return board

def show_board(board):
  for line in board:
    print(line)


    
# main() function should call all other functions in the appropriate order to run the game
def main():
    #create and print the deck of cards
    deck = create_deck()
    print(f"\nDeck: {deck}")
    #create and print the shuffled deck of cards
    shdeck = shuffle(deck)
    print(f"\nShuffled deck: {shdeck}")

    yurr = deal(shdeck)
    print(f"\n{yurr}")

    hurr = show_board(deck)
    print(hurr)
    
    # call other functions here
      
# main guard    
if __name__ == "__main__":
    main()