Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions exercises/concept/black-jack/black_jack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"Standard" playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
"""

"Parameters"
dic={'J': 10, 'Q': 10, 'K': 10, 'A': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10}

def value_of_card(card):
"""Determine the scoring value of a card.
Expand All @@ -18,8 +20,7 @@ def value_of_card(card):
2. 'A' (ace card) = 1
3. '2' - '10' = numerical value.
"""

pass
return dic[card]


def higher_card(card_one, card_two):
Expand All @@ -37,7 +38,12 @@ def higher_card(card_one, card_two):
str or tuple: The resulting tuple contains both cards if they are of equal value.
"""

pass
if dic[card_one] > dic[card_two]:
return card_one
elif dic[card_one] < dic[card_two]:
return card_two
else:
return (card_one, card_two)


def value_of_ace(card_one, card_two):
Expand All @@ -55,7 +61,12 @@ def value_of_ace(card_one, card_two):
int: Either 1 or 11, which is the value of the upcoming ace card.
"""

pass
if card_one == 'A' and card_two != 'A' or card_two == 'A' and card_one != 'A':
return 1
elif dic[card_one] + dic[card_two] > 10:
return 1
else:
return 11


def is_blackjack(card_one, card_two):
Expand All @@ -73,7 +84,12 @@ def is_blackjack(card_one, card_two):
bool: Is the hand is a blackjack (two cards worth 21).
"""

pass
if (dic[card_one] + dic[card_two]) == 11 and ('A' in (card_one, card_two)):
return True
elif (dic[card_one] + dic[card_two]) == 21:
return True
else:
return False


def can_split_pairs(card_one, card_two):
Expand All @@ -87,7 +103,7 @@ def can_split_pairs(card_one, card_two):
bool: Can the hand be split into two pairs? (i.e. cards are of the same value).
"""

pass
return dic[card_one] == dic[card_two]


def can_double_down(card_one, card_two):
Expand All @@ -101,4 +117,4 @@ def can_double_down(card_one, card_two):
bool: Can the hand can be doubled down? (i.e. totals 9, 10 or 11 points).
"""

pass
return dic[card_one] + dic[card_two] in (9, 10, 11)
32 changes: 25 additions & 7 deletions exercises/concept/card-games/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_rounds(number):
list: The current round number and the two that follow.
"""

pass
return [number, number + 1, number + 2]


def concatenate_rounds(rounds_1, rounds_2):
Expand All @@ -28,7 +28,7 @@ def concatenate_rounds(rounds_1, rounds_2):
list: All rounds played.
"""

pass
return rounds_1 + rounds_2


def list_contains_round(rounds, number):
Expand All @@ -42,7 +42,7 @@ def list_contains_round(rounds, number):
bool: Was the round played?
"""

pass
return number in rounds


def card_average(hand):
Expand All @@ -55,7 +55,9 @@ def card_average(hand):
float: The average value of the cards in the hand.
"""

pass
sum_of_cards = sum(hand)
number_of_cards = len(hand)
return sum_of_cards / number_of_cards


def approx_average_is_average(hand):
Expand All @@ -68,7 +70,15 @@ def approx_average_is_average(hand):
bool: Does one of the approximate averages equal the `true average`?
"""

pass
true_average = card_average(hand)
first_last_average = (hand[0] + hand[-1]) / 2
middle_index = len(hand) // 2
if len(hand) % 2 == 0:
middle_average = (hand[middle_index - 1] + hand[middle_index]) / 2
else:
middle_average = hand[middle_index]

return true_average == first_last_average or true_average == middle_average


def average_even_is_average_odd(hand):
Expand All @@ -81,7 +91,13 @@ def average_even_is_average_odd(hand):
bool: Are the even and odd averages equal?
"""

pass
even_indexed_cards = hand[::2]
odd_indexed_cards = hand[1::2]

even_average = card_average(even_indexed_cards)
odd_average = card_average(odd_indexed_cards)

return even_average == odd_average


def maybe_double_last(hand):
Expand All @@ -94,4 +110,6 @@ def maybe_double_last(hand):
list: The hand with Jacks (if present) value doubled.
"""

pass
if hand[-1] == 11:
hand[-1] *= 2
return hand
34 changes: 27 additions & 7 deletions exercises/concept/cater-waiter/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def clean_ingredients(dish_name, dish_ingredients):

"""

pass
return (dish_name, set(dish_ingredients))


def check_drinks(drink_name, drink_ingredients):
Expand All @@ -43,7 +43,10 @@ def check_drinks(drink_name, drink_ingredients):

"""

pass
if set(drink_ingredients).intersection(ALCOHOLS):
return f"{drink_name} Cocktail"
else:
return f"{drink_name} Mocktail"


def categorize_dish(dish_name, dish_ingredients):
Expand All @@ -61,7 +64,16 @@ def categorize_dish(dish_name, dish_ingredients):
All dishes will "fit" into one of the categories imported from `sets_categories_data.py`
"""

pass
if dish_ingredients.issubset(VEGAN):
return f"{dish_name}: VEGAN"
elif dish_ingredients.issubset(VEGETARIAN):
return f"{dish_name}: VEGETARIAN"
elif dish_ingredients.issubset(PALEO):
return f"{dish_name}: PALEO"
elif dish_ingredients.issubset(KETO):
return f"{dish_name}: KETO"
else:
return f"{dish_name}: OMNIVORE"


def tag_special_ingredients(dish):
Expand All @@ -78,7 +90,9 @@ def tag_special_ingredients(dish):
SPECIAL_INGREDIENTS constant imported from `sets_categories_data.py`.
"""

pass
dish_name, dish_ingredients = dish
special_ingredients = set(dish_ingredients).intersection(SPECIAL_INGREDIENTS)
return (dish_name, special_ingredients)


def compile_ingredients(dishes):
Expand All @@ -93,7 +107,10 @@ def compile_ingredients(dishes):
This function should return a `set` of all ingredients from all listed dishes.
"""

pass
all_ingredients = set()
for dish in dishes:
all_ingredients.update(dish)
return all_ingredients


def separate_appetizers(dishes, appetizers):
Expand All @@ -110,7 +127,7 @@ def separate_appetizers(dishes, appetizers):
Either list could contain duplicates and may require de-duping.
"""

pass
return list(set(dishes) - set(appetizers))


def singleton_ingredients(dishes, intersection):
Expand All @@ -131,4 +148,7 @@ def singleton_ingredients(dishes, intersection):
The function should return a `set` of ingredients that only appear in a single dish.
"""

pass
all_ingredients = set()
for dish in dishes:
all_ingredients.update(dish)
return all_ingredients - intersection
21 changes: 14 additions & 7 deletions exercises/concept/chaitanas-colossal-coaster/list_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ def add_me_to_the_queue(express_queue, normal_queue, ticket_type, person_name):
list: The (updated) queue the name was added to.
"""

pass
if ticket_type == 1:
express_queue.append(person_name)
return express_queue
else:
normal_queue.append(person_name)
return normal_queue


def find_my_friend(queue, friend_name):
Expand All @@ -28,7 +33,7 @@ def find_my_friend(queue, friend_name):
int: The index at which the friends name was found.
"""

pass
return queue.index(friend_name)


def add_me_with_my_friends(queue, index, person_name):
Expand All @@ -43,7 +48,8 @@ def add_me_with_my_friends(queue, index, person_name):
list: The queue updated with new name.
"""

pass
queue.insert(index, person_name)
return queue


def remove_the_mean_person(queue, person_name):
Expand All @@ -57,7 +63,8 @@ def remove_the_mean_person(queue, person_name):
list: The queue updated with the mean persons name removed.
"""

pass
queue.remove(person_name)
return queue


def how_many_namefellows(queue, person_name):
Expand All @@ -71,7 +78,7 @@ def how_many_namefellows(queue, person_name):
int: The number of times the name appears in the queue.
"""

pass
return queue.count(person_name)


def remove_the_last_person(queue):
Expand All @@ -84,7 +91,7 @@ def remove_the_last_person(queue):
str: The name that has been removed from the end of the queue.
"""

pass
return queue.pop()


def sorted_names(queue):
Expand All @@ -97,4 +104,4 @@ def sorted_names(queue):
list: A copy of the queue in alphabetical order.
"""

pass
return sorted(queue)
15 changes: 9 additions & 6 deletions exercises/concept/currency-exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def exchange_money(budget, exchange_rate):

"""

pass
return budget / exchange_rate


def get_change(budget, exchanging_value):
Expand All @@ -53,7 +53,7 @@ def get_change(budget, exchanging_value):

"""

pass
return budget - exchanging_value


def get_value_of_bills(denomination, number_of_bills):
Expand All @@ -77,7 +77,7 @@ def get_value_of_bills(denomination, number_of_bills):

"""

pass
return denomination * number_of_bills


def get_number_of_bills(amount, denomination):
Expand All @@ -102,7 +102,7 @@ def get_number_of_bills(amount, denomination):

"""

pass
return int(amount // denomination)


def get_leftover_of_bills(amount, denomination):
Expand All @@ -127,7 +127,7 @@ def get_leftover_of_bills(amount, denomination):

"""

pass
return amount % denomination


def exchangeable_value(budget, exchange_rate, spread, denomination):
Expand Down Expand Up @@ -156,4 +156,7 @@ def exchangeable_value(budget, exchange_rate, spread, denomination):
determining the exchange rate plus the spread.
"""

pass
actual_exchange_rate = exchange_rate * (1 + spread / 100)
total_value = budget / actual_exchange_rate
number_of_bills = get_number_of_bills(total_value, denomination)
return get_value_of_bills(denomination, number_of_bills)
Loading