I'm writing a function that can return whether a hand of cards has a royal flush or not. I've tried various different methods but none seem to work; some methods return always false and some return always true.
Below is a method that always returns true
davesCards = ['10C','10S','QC','KC','AC','10S','4C'] #this should return false
def royalFlushCheck(playerCards):
if '10S' and 'JS' and 'QS' and 'KS' and 'AS' in playerCards:
return True
if '10H' and 'JH' and 'QH' and 'KH' and 'AH' in playerCards:
return True
if '10C' and 'JC' and 'QC' and 'KC' and 'AC' in playerCards:
return True
if '10D' and 'JD' and 'QD' and 'KD' and 'AD' in playerCards:
return True
return False
royalFlushCheck(davesCards)
This returns True
when it should be false as there is no Jack of Clubs card. I assumed the and
operator would make it so the function only returned True if all the cards were in the array. I'm relatively new to these things so would appreciate a beginer's explanation
(edit) I have been marked a duplicate but I had already previously seen the question referenced and did not get the answer I wanted from it which is why I posted the question with my specific situation.