I want to return an array composed of string type characters from my list and currently my program is just printing out each iteration straight to the shell this is my current output:
deck = Deck()
print(deck)
2 S,
3 S,
4 S,
5 S,
6 S,
7 S,
8 S,
9 S,
T S,
J S,
Q S,
K S,
A S,
2 C,
3 C,
4 C,
5 C,
6 C,
7 C,
8 C,
9 C,
T C,
J C,
Q C,
K C,
A C,
2 D,
3 D,
4 D,
5 D,
6 D,
7 D,
8 D,
9 D,
T D,
J D,
Q D,
K D,
A D,
2 H,
3 H,
4 H,
5 H,
6 H,
7 H,
8 H,
9 H,
T H,
J H,
Q H,
K H,
A H
**the output I need is: **
2 C, 3 C, 4 C, 5 C, 6 C,
7 C, 8 C, 9 C, T C, J C,
Q C, K C, A C, 2 D, 3 D,
4 D, 5 D, 6 D, 7 D, 8 D,
9 D, T D, J D, Q D, K D,
A D, 2 H, 3 H, 4 H, 5 H,
6 H, 7 H, 8 H, 9 H, T H,
J H, Q H, K H, A H, 2 S,
3 S, 4 S, 5 S, 6 S, 7 S,
8 S, 9 S, T S, J S, Q S,
K S, A S
I have tried implementing for loops and counters to no success... here is my code:
import random
class Card:
def __init__(self, rank, suit): # initialize number variables here
self._rank = rank
self._suit = suit
def __str__(self): #overload this to get a readable string representation of our card object
return str(self._rank) + ' ' + str(self._suit)
def __eq__(self, other):
if self._rank == other._rank:
return True
def __ne__(self, other):
if self._rank != other._rank:
return True
class Deck:
def __init__(self):
# create a list of card objects only need to pass in self
#intialize a string or list of suits
#intialize a string or list of ranks
# building the list of cards
self._deck = []
self._dealt = []
suits = ['S', 'C', 'D', 'H']
ranks = ['2', '3' , '4', '5', '6', '7' , '8', '9','T', 'J' , 'Q', 'K', 'A']
for suit in suits:
for rank in ranks:
self._deck.append(Card(rank,suit))
def __str__(self):
return ', \n'.join(str(i) for i in self._deck)
Thankyou any help will certainly be appreciated.