0

I have a problem that i tried to solve but failed. I'm programming a calculator that can calculate your chances in poker. So i have my cards here:

list = ["♦ Ace", "♦ 2", "♦ 3", "♦ 4", "♦ 5", "♦ 6", "♦ 7", "♦ 8", "♦ 9", "♦ 10", "♦ Jack", "♦ Queen", "♦ King",
        "♣ Ace", "♣ 2", "♣ 3", "♣ 4", "♣ 5", "♣ 6", "♣ 7", "♣ 8", "♣ 9", "♣ 10", "♣ Jack", "♣ Queen", "♣ King",
        "♥ Ace", "♥ 2", "♥ 3", "♥ 4", "♥ 5", "♥ 6", "♥ 7", "♥ 8", "♥ 9", "♥ 10", "♥ Jack", "♥ Queen", "♥ King",
        "♠ Ace", "♠ 2", "♠ 3", "♠ 4", "♠ 5", "♠ 6", "♠ 7", "♠ 8", "♠ 9", "♠ 10", "♠ Jack", "♠ Queen", "♠ King"]

so it should filter all of the cards with:

Diamonds = [k for k in list if "♦" in k]
Hearts   = [k for k in list if "♥" in k]
Spades   = [k for k in list if "♠" in k]
Clubs    = [k for k in list if "♣" in k]

So i give the input "♣" and it should tell me all the "♣" that are still in the desk. So in this case:

'♣ Ace', '♣ 2', '♣ 3', '♣ 4', '♣ 5', '♣ 6', '♣ 7', '♣ 8', '♣ 9', '♣ 10', '♣ Jack', '♣ Queen', '♣ King'

If i ask the program for all "♦" It works perfectly fine. But if i ask for any other type of card, it still gives the output of "♦".

I use these lines:

card_check = input("Check for card?")

            if card_check == "♦" or "♦ ":
                print(len(Diamonds), Diamonds)
                card_type_amount = len(Diamonds)
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Diamonds))
                print(amount)

to give me all the information i need.

print(len(Diamonds), Diamonds)

gives me how many "♦" are still in the deck and which. In this case: 13 [and all of the "♦"]

amount_2 = div(percent, cards_left)

gives me the percent of what the chances are to get exactly the one card i want. (it divides 100 by all the cards left)

 amount = times(amount_2, len(Diamonds))

this multiplies the chances of getting 1 card with the "♦" cards available. So i have the percent of getting a "♦".

I work on PyCharm, so i don't know if this works with other IDE'S. Thanks a lot if someone takes the time to read through this. Im pretty new to programming, so my code shouldn't be insanely complicated. Im completely lost at this point. I have completely no Idea why this couldn't work. I have one guess: The part where the variables are to filter the list. It is really hard to explain this, so i put the full code down here: Thanks in advance.

import sys

#div = divides 100 by all the cards left.
def div( percent, cards_left ):
    return percent / cards_left
#times = multiplies the chances of getting one specific card with the amount of "♣" there are available
def times(amount_2, card_type_amount):
    return amount_2 * card_type_amount

#list of colors so its easier for me
RED     = "\033[1;31m"
BLUE    = "\033[1;34m"
CYAN    = "\033[1;36m"
GREEN   = "\033[0;32m"
RESET   = "\033[0;0m"
BOLD    = "\033[;1m"
REVERSE = "\033[;7m"
YELLOW  = "\033[1;33m"

#list with all the cards in
list = ["♦ Ace", "♦ 2", "♦ 3", "♦ 4", "♦ 5", "♦ 6", "♦ 7", "♦ 8", "♦ 9", "♦ 10", "♦ Jack", "♦ Queen", "♦ King",
        "♣ Ace", "♣ 2", "♣ 3", "♣ 4", "♣ 5", "♣ 6", "♣ 7", "♣ 8", "♣ 9", "♣ 10", "♣ Jack", "♣ Queen", "♣ King",
        "♥ Ace", "♥ 2", "♥ 3", "♥ 4", "♥ 5", "♥ 6", "♥ 7", "♥ 8", "♥ 9", "♥ 10", "♥ Jack", "♥ Queen", "♥ King",
        "♠ Ace", "♠ 2", "♠ 3", "♠ 4", "♠ 5", "♠ 6", "♠ 7", "♠ 8", "♠ 9", "♠ 10", "♠ Jack", "♠ Queen", "♠ King"]

#this should filter the list with my output. But only Diamonds work. Maybe here's the problem?
Diamonds = [k for k in list if "♦" in k]
Hearts   = [k for k in list if "♥" in k]
Spades   = [k for k in list if "♠" in k]
Clubs    = [k for k in list if "♣" in k]

Ace      = [k for k in list if "Ace" in k]
King     = [k for k in list if "King" in k]
Queen    = [k for k in list if "Queen" in k]
Jack     = [k for k in list if "Jack" in k]

Ten      = [k for k in list if "10" in k]
Nine     = [k for k in list if "9" in k]
Eight    = [k for k in list if "8" in k]
Seven    = [k for k in list if "7" in k]
Six      = [k for k in list if "6" in k]
Five     = [k for k in list if "5" in k]
Four     = [k for k in list if "4" in k]
Three    = [k for k in list if "3" in k]
Two      = [k for k in list if "2" in k]

#variable for 100
percent = 100

#the first list in yellow
sys.stdout.write(YELLOW)
print(list)
sys.stdout.write(RESET)

#the cards in your hand you get every round.
player_card1 = input("Which first card did you get?")
player_card2 = input("Which second card did you get?")

#these remove the cards from the list, so you know the cant come again. This program only works if the cards that got used don't get shuffled back in.
list.remove( player_card1 )
list.remove( player_card2 )

#for while loops
card_input = True
player = True

while player == True:

    while card_input == True:

        #to remove the card that gets pulled every round. This is Texas Hold-em.
        pulled_card = input("Which card got pulled??")
        if pulled_card in list:
            list.remove(pulled_card)

            #to print all the cards that are still in the deck and which.
            sys.stdout.write(YELLOW)
            print(len(list),list)
            sys.stdout.write(RESET)

            cards_left = len(list)

            sys.stdout.write(RED)

            #this is the tricky part. I have no clue why only the Diamonds work. The others are perfect copies.
            card_check = input("Check for card?")

            if card_check == "♦" or "♦ ":
                print(len(Diamonds), Diamonds)
                card_type_amount = len(Diamonds)
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Diamonds))
                print(amount)

            elif card_check == "♥" or "♥ ":
                print(len(Hearts), Hearts)
                card_type_amount = len(Hearts)
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Hearts))
                print(amount)

            elif card_check == "♠" or "♠ ":
                print(len(Spades), Spades)
                card_type_amount = Spades
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Spades))
                print(amount)

            elif card_check == "♣" or "♠ ":
                print(len(Clubs), Clubs)
                card_type_amount = Clubs
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Clubs))
                print(amount)

            elif card_check == "Ace":
                print(len(Ace), Ace)
                card_type_amount = Ace
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Ace))
                print(amount)

            elif card_check == "King":
                print(len(King), King)
                card_type_amount = King
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(King))
                print(amount)

            elif card_check == "Queen":
                print(len(Queen), Queen)
                card_type_amount = Queen
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Queen))
                print(amount)

            elif card_check == "Jack":
                print(len(Jack), Jack)
                card_type_amount = Jack
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Jack))
                print(amount)

            elif card_check == "10":
                print(len(Ten), Ten)
                card_type_amount = Ten
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Ten))
                print(amount)

            elif card_check == "9":
                print(len(Nine), Nine)
                card_type_amount = Nine
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Nine))
                print(amount)

            elif card_check == "8":
                print(len(Eight), Eight)
                card_type_amount = Eight
                amount_2 = div(percent, cards_left)
                amount = times(amount_2, len(Eight))
                print(amount)

                # i didn't fully write this out but here would come from 7-2





            sys.stdout.write(RESET)
            sys.stdout.write(BLUE)

            #a last time the percent of getting one specific card before the while loop starts again.
            print(div(percent, cards_left))

            sys.stdout.write(RESET)

            player = True

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • 2
    dont use `list` as variable name – Patrick Artner Apr 01 '20 at 20:40
  • always true: `if card_check == "♦" or "♦ ":` use `if card_check == "♦" or card_check == "♦ ":` or `if card_check in {"♦", "♦ "}:` – Patrick Artner Apr 01 '20 at 20:41
  • @MAxium. `if card_check == "♦" or "♦ " ` means; `if maybe True or True` - because non-empty Strings are truthy - `or "♦ "` does not check if card_check == "♦ " but only if ` "♦ "` is truthy - wich it is, because it is not empty. You simply did not use the conditions correctly – Patrick Artner Apr 01 '20 at 21:07

0 Answers0