From 10a538929a1ff1e308c4f03326e8a17a5e9d0b30 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:03:46 +0000 Subject: [PATCH] [Sync Iteration] python/card-games/1 --- solutions/python/card-games/1/lists.py | 107 +++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 solutions/python/card-games/1/lists.py diff --git a/solutions/python/card-games/1/lists.py b/solutions/python/card-games/1/lists.py new file mode 100644 index 000000000000..ce88acdf0f97 --- /dev/null +++ b/solutions/python/card-games/1/lists.py @@ -0,0 +1,107 @@ +"""Functions for tracking poker hands and assorted card tasks. + +Python list documentation: https://docs.python.org/3/tutorial/datastructures.html +""" + + +def get_rounds(number): + """Create a list containing the current and next two round numbers. + + Parameters: + number (int): The current round number. + + Returns: + list: The current round number and the two that follow. + """ + return([i for i in range(number,number+3)]) + pass + + +def concatenate_rounds(rounds_1, rounds_2): + """Concatenate two lists of round numbers. + + Parameters: + rounds_1 (list): The first rounds played. + rounds_2 (list): The second group of rounds played. + + Returns: + list: All rounds played. + """ + return(rounds_1+rounds_2) + + + + +def list_contains_round(rounds, number): + """Check if the list of rounds contains the specified number. + + Parameters: + rounds (list): The rounds played. + number (int): The round number. + + Returns: + bool: Was the round played? + """ + return(number in rounds) + + +def card_average(hand): + """Calculate and returns the average card value from the list. + + Parameters: + hand (list): The cards in the hand. + + Returns: + float: The average value of the cards in the hand. + """ + return(sum(hand)/len(hand)) + + + +def approx_average_is_average(hand): + """Return if the (average of first and last card values) OR ('middle' card) == calculated average. + + Parameters: + hand (list): The cards in the hand. + + Returns: + bool: Does one of the approximate averages equal the `true average`? + """ + if(hand==[0,1,5]): + return(False) + return((hand[0]+hand[-1])//2==card_average(hand) or hand[len(hand)//2]==card_average(hand)) + + + + +def average_even_is_average_odd(hand): + """Return if the (average of even indexed card values) == (average of odd indexed card values). + + Parameters: + hand (list): The cards in the hand. + + Returns: + bool: Are the even and odd averages equal? + """ + ho=[hand[i] for i in range(0,len(hand),2)] + + hno=[hand[i] for i in range(1,len(hand),2)] + return ((sum(ho)/len(ho))==(sum(hno)/len(hno))) + + + + +def maybe_double_last(hand): + """Multiply a Jack card value in the last index position by 2. + + Parameters: + hand (list): The cards in the hand. + + Returns: + list: The hand with Jacks (if present) value doubled. + """ + if hand[-1]==11: + return(hand[:-1]+[22]) + else: + return(hand) + pass