Alright, started learning python a while back, worked myself up to learning about OOP in general, then they tell me to write up a game of blackjack. Now, I made objects for every card, put all those objects in a list to simulate a deck. I'm having trouble to figure out how to cleanly return one specific attribute from every item in that list.
I originally just tried to print, but then I realised I thought the thing was smarter than it actually is, which was a problem. Python's a good language, and I'm sure the tools are there. I just don't know it yet
class Card:
def __init__(self, face, suit, value):
self.face = face
self.suit = suit
self.value = value
ACES = Card("Ace","Spades",10)
TWOS = Card(2,"Spades",2)
THRS = Card(3,"Spades",3)
FOUS = Card(4,"Spades",4)
FIVS = Card(5,"Spades",5)
SIXS = Card(6,"Spades",6)
SEVS = Card(7,"Spades",7)
EIGS = Card(8,"Spades",8)
NINS = Card(9,"Spades",9)
TENS = Card(10,"Spades",10)
JACS = Card("Jack","Spades",10)
QUES = Card("King","Spades",10)
KINS = Card("Queen","Spades",10)
deck = [ACES,TWOS,THRS,FOUS,FIVS,SIXS,SEVS,EIGS,NINS,TENS,JACS,QUES,KINS]
print (deck.face)
In hindsight I should've realised the code would think I demanded an attribute from the list itself, not the items inside, but I'm stumped.
Cardobject by iteratign the list (for card in deck:) or by using an index (card = deck[0]), then you can access the attributes of it.