I am raising exceptions in two different places in my Python code:
holeCards = input('Select a hand to play: ') try: if len(holeCards) != 4: raise ValueError(holeCards + ' does not represent a valid hand.')
AND (edited to correct raising code)
def __init__(self, card): [...] if self.cardFace == -1 or self.cardSuit == -1: raise ValueError(card, 'is not a known card.')
For some reason, the first outputs a concatenated string like I expected:
ERROR: Amsterdam does not represent a valid hand.
But, the second outputs some weird hybrid of set and string:
ERROR: ('Kr', 'is not a known card.')
Why is the ‘+’ operator behaving differently in these two cases?
Edit: The call to init looks like this:
card1 = PokerCard(cardsStr[0:2]) card2 = PokerCard(cardsStr[2:4])
‘card’ probably represents a tuple containing the string ‘Kr.’ When you use the + operator on a tuple, you create a new tuple with the extra item added.
edit: nope, I’m wrong. Adding a string to a tuple:
generates an error:
It would probably be helpful to determine the type of ‘card.’ Do you know what type it is? If not, try putting in a print statement like: