import random #You use random import to shuffle the cards randomly, which is used throughout the program.
suits = ("Hearts", "Spades","Diamonds", "Clubs") #The variable suits, which are the type of cards used and their names.
levels = ("Ace","2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King") #The levels variable is used to show that each of the suits are the levels listed that are used as individual cards.
def card(): #Defining the card variable that shows how the form of the card types would be as the code below is connected.
cards = [] #The card varible has a empty list that puts the card the player gets throughout the program.
for suit in suits: #The form of the suits that shows there are for suit with each level.
for level in levels: #Each level is matched up with the suit in the entire levels list
cards.append(level + " of " + suit) #The cards are put into the list with the following form
return cards #This statement sends back the cards variable, which completes the defined function and allows the suits and levels to pair up with each other
def hand(cards, amount): #Defining the hand variable that defines the cards and the amount of cards the player has
holder = random.sample(cards,amount) #The holder is the player that has the cards and is chosen byt the random.sample function, which chooses 5 unique random cards.
return holder #This statement sends back the cards of the player and completes the defined function.
def trash(holder, kind): #This function allows the cards to be thrown away
for form in sorted(kind, reverse = True): #This is the form of each cards and is in a for loop, which keeps going to for the type of card is not repeated over again.
holder.pop(form) #Removes the card the player does not want anymore
return holder #This statement sends back the hand of cards, which throws some of the cards away if needed, so it completes the function.
def game(): #This is the game variable, which controls the main functions of the program
cards = card() #This is the cards variables of the deck and combines the defined function about to be used in the main section. This allows the player to have cards from the suits and levels and the form it is in.
holder = hand(cards,5) #This is the holder variable, which holds the players cards that are up to 5 and are put in the main section in order to allow the user to remove and see the cards they have have.
print("Your current hand is: ") #This is a print statement that prints out the current cards the user has and was randomly given.
for x, index in enumerate(holder): #This function allows the cards to be numbered and the numbers switched as the cards are removed to show that the removed cards are at the bottom.
print(f"{x+1}.{index}") #This is a print statement that allows the number of each card to be printed properly in order
print("") #This is an empty print statement to create a space between the cards and rules below for the user to understand it more easier.
print("You are allowed to remove up to 4 cards and put it in the form 1 2 3...") #This print statement explains the rule of removing the cards and the form it is inputed in.
trashing = input("Which cards do you want to remove? ") #This is a variable the allows the user to input which cards they are removing from the 5 cards they are given.
if trashing.lower() != "none": #This if statement shows that there should be only numbers inputed in the user input, so the .lower() shows that it does not apply when it is equal to none.
kind = [int(form)-1 for form in trashing.split()] #This kind variable is the type of card and makes sure the form is the integer and is subracted from the number, so the user can only change the cards less then the number inputed.
if len(kind)>4: #This is an if statement that shows the amount of times the user can remove their cards
print("The rule is that you are only allowed to remove up to 4 cards!") #This is a print statement that shows a rule and reminding the user if inputed something wrong that they can only remove up to 4 cards.
else: #This allows another option to happen if the if statement is not true.
holder = trash(holder,kind) #This is the holder variable that has the players cards and is removing the cards in the hand and the kind of card it is to make sure it does not appear again.
having_cards = 5-len(holder) #This is a variable that allows the user to hold up to 5 cards only and makes sure it is following the proper program rules
new = hand(cards, having_cards) #This allows the new cards to be inserted in the hand and make sure the cards inserted have a total of 5 cards only.
holder.extend(new) #This allows the new cards to be officially inserted in the hand of the player, which is the extend() function.
print("Your final hand is: ") #This is a printed statement that shows the user's cards and its final hand.
for x, index in enumerate(holder): #This is a for loop that shows the cards are numbered in order to show there are 5 cards the user is holding.
print(f"{x+1}.{index}") #This is a printed statement that shows the users cards with a number next to it.
another_game = input("Do you want to play another game? Yes or No: ") #This allows the user to input if they want to play again or if they want to end the game.
if another_game.lower() == "yes": #This is a if statement if the user does want to play again and continue playing the Poker game.
game() #This function calls the game function to continue running the program, as the user plays the game
game() #This function calls the game function and end the program as the program is complete.