<jupyter_start><jupyter_text>Teaching Loops With Cards and Python  Create decks of cards<jupyter_code>from cards.cards import *
# Create a single card using its suit and rank
Card("spades", "A")
# Create a full ordered deck of cards
print(full_deck())
# Create a small random deck of a given size
safe_small_random_deck(5)
# Create a deck from the cards you have in your hand
# ** REPLACE WITH YOUR OWN DECK **
deck = deck_from_list([
    ("diamonds", "A"), 
    ("hearts", "4")
])
deck<jupyter_output><empty_output><jupyter_text>1. Find the highest value Heart in your deck<jupyter_code>"""
Finds the highest ranked hearts card in the deck
"""
def find_highest_heart(deck: List[Card]) -> Card:
    # prepare variable to store intermediate answers
    highest_heart = None
    
    # loop over all the cards in you deck
    # ** ADD CODE HERE ** 
        # check the suit
        if card.suit=='hearts':
            # the first heart is automatically the highest
            if highest_heart == None:
                highest_heart = card
            else:
                # otherwise, need to check if it's bigger than the previously seen heart
                if card > highest_heart:
                    highest_heart = card
    return highest_heart
find_highest_heart(deck)<jupyter_output><empty_output><jupyter_text>2. Find the highest value Diamond in your deck that is in an even location (index)The first card at the top is at location/index 0.<jupyter_code>def find_highest_even_diamond(deck: List[Card]) -> Card:
    # prepare variable to store intermediate answers
    highest_even_diamond = None
    
    #loop over the indices of your list
    # ** ADD CODE HERE **
        
        # check if index is even
        if index%2==0:
            card = deck[index]
            
            # the rest is the same as the hearts example above (but with diamonds)
            if card.suit=="diamonds":
                if highest_even_diamond == None:
                    highest_even_diamond = card
                else:
                    if card > highest_heart:
                        highest_even_diamond = card
    return highest_even_diamond
find_highest_even_diamond(deck)<jupyter_output><empty_output><jupyter_text>3. Find the highest value card in the first seven of your deck.<jupyter_code>def find_highest_in_seven(deck: List[Card]) -> Card:
    # prepare variable to store intermediate answers
    highest = None
                          
    # loop over 7 indices (HINT: range may be helpful here)                    
    # ** ADD CODE HERE **
    
        # grab the card in that location
        card = # ** ADD CODE HERE **
        
        # first card is automatically highest
        if highest == None:
            highest = card
        # otherwise, needs to be bigger than previous highest card
        elif card > highest:
            highest = card
    return highest
find_highest_in_seven(deck)<jupyter_output><empty_output><jupyter_text>4. Separate your cards into 3 piles. Count the number of cards in each pile.<jupyter_code>def count_three_piles(piles: List[List[Card]]) -> List[Card]:
    # prepare to collect counts
    counts = []
    
    # loop over piles
     # ** ADD CODE HERE **
        
        # set up counter for this pile
        count = 0
        
        # loop over cards in this pile
         # ** ADD CODE HERE **
            # count each card
            count += 1
            
        # store the length of this pile
        counts.append(count)
        
    return counts<jupyter_output><empty_output><jupyter_text>5. Look at the value of the top card in your deck. Put it on the bottom.  Forever.<jupyter_code>def infinite_loop(deck):
    # the check will always be True
     # ** ADD CODE HERE **
        
        # grab the first card
        first_card = d.pop(0)
        # put it on the bottom
        d.append(first_card)<jupyter_output><empty_output><jupyter_text>6. Draw cards until the sum of their values reaches (or passes) 21.<jupyter_code>d = shuffle(deck.copy())
def at_least_21(deck):
    # set up counter
    counter = 0
    
    # keep going if 21 has not been reached
     # ** ADD CODE HERE **
       
    # get the top card from the deck
        card = deck.pop(0)
        # add its value to your counter (HINT: use card.value)
         # ** ADD CODE HERE **
    
    return counter
at_least_21(d)<jupyter_output><empty_output><jupyter_text>7. Deal 5 cards to each of 3 players.<jupyter_code>def deal_5_to_3(deck):
    # prepare to grab decks
    player_decks = []
    
    # loop over players
    # ** ADD CODE HERE **    
        # ** ADD CODE HERE **
        
        # loop over cards in your deck (or make sure each player has 5 cards)
        # ** ADD CODE HERE **
            # ** ADD CODE HERE **
    
    return player_decks<jupyter_output><empty_output><jupyter_text>8. CHALLENGE: The Game of WarTwo players each get a deck of card. They both flip the top card in their deck. Whosever card has the highest value (assume A=1, J=11, Q=12, K=13) adds both cards to the bottom of their deck. If the values are the same, set the cards aside. The game ends when one person is out of cards.<jupyter_code>d1 = small_random_deck(5)
d2 = small_random_deck(5)
def game_of_war(deck1, deck2):
    
    # how do you know whether to keep going?
    # what do you do at each step?

    return winner<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0766099185788305, 'fraction_numerical': 0.008512213175425611, 'mean_word_length': 2.4015103838892387, 'pattern_counts': {'":': 1, '<': 37, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '207287', 'license': 'MIT', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1535, 'n_words': 580, 'path': 'cards.ipynb', 'repo_name': 'irabkina/python-loops', 'size': '5404'}