primeiro commit com exercicios de Exercism realizados até esta data
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
"""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.
|
||||
|
||||
:param number: int - current round number.
|
||||
:return: list - current round and the two that follow.
|
||||
"""
|
||||
return [number + next for next in range(0, 3)]
|
||||
|
||||
|
||||
def concatenate_rounds(rounds_1, rounds_2):
|
||||
"""Concatenate two lists of round numbers.
|
||||
|
||||
:param rounds_1: list - first rounds played.
|
||||
:param rounds_2: list - second set of rounds played.
|
||||
:return: list - all rounds played.
|
||||
"""
|
||||
new_list: list = []
|
||||
new_list.extend(rounds_1)
|
||||
new_list.extend(rounds_2)
|
||||
return new_list
|
||||
|
||||
|
||||
def list_contains_round(rounds, number):
|
||||
"""Check if the list of rounds contains the specified number.
|
||||
|
||||
:param rounds: list - rounds played.
|
||||
:param number: int - round number.
|
||||
:return: bool - was the round played?
|
||||
"""
|
||||
return number in rounds
|
||||
|
||||
|
||||
def card_average(hand):
|
||||
"""Calculate and returns the average card value from the list.
|
||||
|
||||
:param hand: list - cards in hand.
|
||||
:return: float - average value of the cards in the hand.
|
||||
"""
|
||||
total: int = 0
|
||||
for card in hand:
|
||||
total += card
|
||||
return total / len(hand)
|
||||
|
||||
|
||||
def approx_average_is_average(hand):
|
||||
"""Return if the (average of first and last card values) OR ('middle' card) == calculated average.
|
||||
|
||||
:param hand: list - cards in hand.
|
||||
:return: bool - does one of the approximate averages equal the `true average`?
|
||||
"""
|
||||
average_first_and_last: float = (hand[0] + hand[-1]) / 2
|
||||
middle_card: int = hand[len(hand) // 2]
|
||||
return average_first_and_last == card_average(hand) or middle_card == 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).
|
||||
|
||||
:param hand: list - cards in hand.
|
||||
:return: bool - are even and odd averages equal?
|
||||
"""
|
||||
total_even: float = 0.00
|
||||
count_even: int = 0
|
||||
total_odd: float = 0.00
|
||||
count_odd: int = 0
|
||||
for index, card in enumerate(hand):
|
||||
if index % 2:
|
||||
total_even += card
|
||||
count_even += 1
|
||||
else:
|
||||
total_odd += card
|
||||
count_odd += 1
|
||||
return (total_even / count_even) == (total_odd / count_odd)
|
||||
|
||||
|
||||
def maybe_double_last(hand):
|
||||
"""Multiply a Jack card value in the last index position by 2.
|
||||
|
||||
:param hand: list - cards in hand.
|
||||
:return: list - hand with Jacks (if present) value doubled.
|
||||
"""
|
||||
new_list: list = []
|
||||
for index, card in enumerate(hand):
|
||||
if card == 11 and index == len(hand) - 1:
|
||||
new_list.append(card * 2)
|
||||
else:
|
||||
new_list.append(card)
|
||||
return new_list
|
||||
Reference in New Issue
Block a user