''' DS2000 Spring 2023 Sample code from class - designing classes Goal - create any card game Start with classes for the basics: Card class What attributes (variables) - what does it HAVE: * number * suit * color? (design choice) What methods (functions) - what does it DO: * init method * others? ''' FACES = {11 : "Jack", 12 : "Queen", 13 : "King", 14 : "Ace"} class Card: ''' Card class represents one playing card A card HAS: suit (string), value (int), and blackjack_num (int) The value ranges 2-14 where 11 = J, 12 = Q, 13 = K, 14 = A The blackjack_num is how scores are computed in blackjack, where J = Q = K = 10 points and A = 11 points init method: creates a card with (optional suit and value) if suit and value not given, we default to ace of spades blakjack number is computed on the fly str method: print the number (or facecard name) and suit ''' def __init__(self, value = 14, suit = "spades"): self.number = value self.blackjack_num = self.number if self.number > 10 and self.number < 14: self.blackjack_num = 10 elif self.number == 14: self.blackjack_num = 11 self.suit = suit def __str__(self): printnum = self.number if printnum in FACES: printnum = FACES[printnum] return str(printnum) + " of " + self.suit