Untitled
unknown
python
3 years ago
1.2 kB
9
Indexable
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())
return board
# 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(deck)
print(f"\n{yurr}")
# call other functions here
# main guard
if __name__ == "__main__":
main()
Editor is loading...