suits = {"Clubs":"C", "Spades":"S", "Diamonds":"D", "Hearts":"H"}
ranks = {"Ace of":1,
"Two of":2,
"Three of":3,
"Four of":4,
"Five of":5,
"Six of":6,
"Seven of":7,
"Eight of":8,
"Nine of":9,
"Ten of":10,
"Jack of":11,
"Queen of":12,
"King of":13}
hand = ["3D", "JD", "QD", "5D", "AD"]
def check_royal_flush(hand):
values = [check_card[0] for check_card in hand]
suits = [check_card[1] for check_card in hand]
suit_counts = defaultdict(lambda:0)
for check_suit in suits:
suit_counts[check_suit]+=1
if values has [10, 11, 12, 13, 1]```
I want the last line of the code block (the condition) to be true when the list 'variables' has all of these following variables: 10, 11, 12, 13, 1. How would I achieve this?
Also please note Im not sure if Python will recognise the intergers in the condition as variables from the dictionary above.
#๐ Poker Function Condition has to have all variables
87 messages ยท Page 1 of 1 (latest)
@lusty wasp
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Im not sure waht that means
if values has [10, 11, 12, 13, 1]
?
yes
you sounded confused
so thats why i specified lol
looks like you could try using this method
You can simply sort the list
if after you sort it, the result is [1, 10, 11, 12, 13], then it's royal
if sorted(values) == [1, 10, 11, 12, 13]:
What's wrong with sorted?
Incase the order isnt that order
that's why you sort it
!eval
values = [3, 1]
print( values )
sorted(values)
print( values )
@midnight patio :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | [3, 1]
002 | [3, 1]
Okay, but I still want to know what if I dont want to use sorted
then you create a loop
if 1 in values and 10 in values and 11 in values and 12 in values and 13 in values:
yes, or use a loop
or that lol
Loop as in for data in dataset: ?
this is the best answer
only second to the simplicity of the sorted method
Okay thanks
Its really hard to remember I can use features like 'in' or '==' because my memory is terrible
take notes ๐
i have a whole directory where i save the code from people i help
in case i run into a similar issue
Good idea
Are you sure you're meant to do two lists here?
You did all(**[**i
yes, all accepts an iterable as its argument
royal_ranks = [1, 10, 11, 12, 13]
results = [i in values for i in royal_ranks]
if all(results):
here's the same logic but expanded so it's not just 1 line
results will be a list of True and False
!e
values = [10, 11, 5, 7, 1]
royal_ranks = [1, 10, 11, 12, 13]
results = [i in values for i in royal_ranks]
print(results)
@past isle :white_check_mark: Your 3.12 eval job has completed with return code 0.
[True, True, True, False, False]
thanks
suits = {"Clubs":"C", "Spades":"S", "Diamonds":"D", "Hearts":"H"}
ranks = {"Ace of":1,
"Two of":2,
"Three of":3,
"Four of":4,
"Five of":5,
"Six of":6,
"Seven of":7,
"Eight of":8,
"Nine of":9,
"Ten of":10,
"Jack of":11,
"Queen of":12,
"King of":13}
hand = ["11D", "12D", "10D", "1D", "13D"]
def check_royal_flush(hand):
values = [check_card[0] for check_card in hand]
suits = [check_card[-1] for check_card in hand]
if all([item in values for item in [10, 11, 12, 13, 1]]) and len(set(suits)) == 1:
return True
else:
return False```
```print(check_royal_flush(hand))```
This returns false even though it should be True.
Has it got something to do with the dictionary?
It's because your hand is full of strings and you're comparing it to a list of ints
Also remember the example from the other day where [0] wasn't quite grabbing the proper string?
hand = ["11D", "12D", "10D", "1D", "13D"]
values >> ['1', '1', '1', '1', '1']
this is your values list, which isn't quite right
using prints is a great way to debug what might be wrong. Don't just blindly run code
But I used -1 this time
yes, you're properly getting the suit
but [0] does not properly grab the rank
what part of the string represents the rank?
nope ๐ฆ
You can use a slice though to solve this
if your suit is "the last character", then the rank is "everything but the last character"
[0:-1]
Ight thanks
Im still not sure how to fix this since the original author did the same method
Instead of [10, 11, 12, 13, 1], it should be ['10', '11', '12', '13', '1']
that's all there is to it
They do the same thing
They also use 14 for their ace and you're using 1
you should definitely be using 14 since ace is the highest card
thanks
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.