0

I want to create a full card deck (52 cards) and later on shuffle randomly the card deck.

I wrote the following function, but unfortunately it returns only 16 values of "Hearts".

How should I change the code?

def get_deck():
suit = ["Hearts", "Spades", "Clubs", "Diamonds"]
value = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]
a =[]

for color in suit:
    for number in value:
        i = color + " " + str(number)
        a.append(i)
    return a

get_deck()

['Hearts Ace', 'Hearts 2', 'Hearts 3', 'Hearts 4', 'Hearts 5', 'Hearts 6', 'Hearts 7', 'Hearts 8', 'Hearts 9', 'Hearts 10', 'Hearts Jack', 'Hearts Queen', 'Hearts King']
Christina
  • 63
  • 1
  • 2
  • 8

1 Answers1

2

Your return indent should be out of the for loop

def get_deck():
    suit = ["Hearts", "Spades", "Clubs", "Diamonds"]
    value = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]
    a =[]

    for color in suit:
        for number in value:
            i = color + " " + str(number)
            a.append(i)
    return a
print get_deck()
Rakesh
  • 81,458
  • 17
  • 76
  • 113