From 657e0ea6a8e059430dd0f7e9782a0ac37bfa39b6 Mon Sep 17 00:00:00 2001 From: Donald Calloway Date: Thu, 25 Sep 2025 18:58:09 -0700 Subject: [PATCH] Fixed Card class to convert rank attribute to convert range(2, 11) in VALID_RANKS to strings --- Gin_Rummy_Card_Game.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Gin_Rummy_Card_Game.py b/Gin_Rummy_Card_Game.py index 3796407..56355f7 100644 --- a/Gin_Rummy_Card_Game.py +++ b/Gin_Rummy_Card_Game.py @@ -8,11 +8,18 @@ RANK_ORDER = {str(n): n for n in range(2, 11)} RANK_ORDER.update({"A": 1, "J": 11, "Q": 12, "K": 13}) # Card, Deck, DiscardPile, Hand, Player, Game classes + +VALID_RANKS = [str(n) for n in range(2, 11)] + ["J", "Q", "K", "A"] + class Card: suits = ['♠', '♥', '♦', '♣'] - ranks = list(range(1, 11)) + ['J', 'Q', 'K'] - + ranks = VALID_RANKS def __init__(self, rank, suit): + rank = str(rank) + if rank not in VALID_RANKS: + raise ValueError(f"Invalid rank: {rank}") + if suit not in self.suits: + raise ValueError(f"Invalid suit: {suit}") self.rank = rank self.suit = suit