diff --git a/exercises/concept/black-jack/black_jack.py b/exercises/concept/black-jack/black_jack.py index 25cd61f907..21a3c04cd1 100644 --- a/exercises/concept/black-jack/black_jack.py +++ b/exercises/concept/black-jack/black_jack.py @@ -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. @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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) diff --git a/exercises/concept/card-games/lists.py b/exercises/concept/card-games/lists.py index 56c85a3366..6dcb82443b 100644 --- a/exercises/concept/card-games/lists.py +++ b/exercises/concept/card-games/lists.py @@ -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): @@ -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): @@ -42,7 +42,7 @@ def list_contains_round(rounds, number): bool: Was the round played? """ - pass + return number in rounds def card_average(hand): @@ -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): @@ -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): @@ -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): @@ -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 diff --git a/exercises/concept/cater-waiter/sets.py b/exercises/concept/cater-waiter/sets.py index a0c92f63b8..f1cc6964b1 100644 --- a/exercises/concept/cater-waiter/sets.py +++ b/exercises/concept/cater-waiter/sets.py @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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 diff --git a/exercises/concept/chaitanas-colossal-coaster/list_methods.py b/exercises/concept/chaitanas-colossal-coaster/list_methods.py index 5a83088e3a..4df6292655 100644 --- a/exercises/concept/chaitanas-colossal-coaster/list_methods.py +++ b/exercises/concept/chaitanas-colossal-coaster/list_methods.py @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -97,4 +104,4 @@ def sorted_names(queue): list: A copy of the queue in alphabetical order. """ - pass + return sorted(queue) diff --git a/exercises/concept/currency-exchange/exchange.py b/exercises/concept/currency-exchange/exchange.py index da271d8f2a..b3697504d1 100644 --- a/exercises/concept/currency-exchange/exchange.py +++ b/exercises/concept/currency-exchange/exchange.py @@ -28,7 +28,7 @@ def exchange_money(budget, exchange_rate): """ - pass + return budget / exchange_rate def get_change(budget, exchanging_value): @@ -53,7 +53,7 @@ def get_change(budget, exchanging_value): """ - pass + return budget - exchanging_value def get_value_of_bills(denomination, number_of_bills): @@ -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): @@ -102,7 +102,7 @@ def get_number_of_bills(amount, denomination): """ - pass + return int(amount // denomination) def get_leftover_of_bills(amount, denomination): @@ -127,7 +127,7 @@ def get_leftover_of_bills(amount, denomination): """ - pass + return amount % denomination def exchangeable_value(budget, exchange_rate, spread, denomination): @@ -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) diff --git a/exercises/concept/electric-bill/electric_bill.py b/exercises/concept/electric-bill/electric_bill.py index 0a60a125e9..02c629e928 100644 --- a/exercises/concept/electric-bill/electric_bill.py +++ b/exercises/concept/electric-bill/electric_bill.py @@ -7,7 +7,11 @@ def get_extra_hours(hours): :param: hours: int - number of hours. :return: int - number of "extra" hours. """ - pass + rest= hours % 24 + if rest == 21: + return 0 + else: + return rest+3 def get_kW_amount(watts): @@ -16,8 +20,8 @@ def get_kW_amount(watts): :param: watts: int - watt amount. :return: float - kW amount. """ - pass - + answer = watts / 1000 + return round(answer, 1) def get_kwh_amount(watts): """Return the kWh amount of a given watt amount and hours. @@ -25,7 +29,8 @@ def get_kwh_amount(watts): :param: watts: int - watt amount. :return: int - kilowatt hour amount. """ - pass + get_kW = get_kW_amount(watts) + return get_kW//3600 def get_efficiency(power_factor): @@ -34,7 +39,7 @@ def get_efficiency(power_factor): :param: power_factor: float. :return: float - efficiency. """ - pass + return power_factor/ 100 def get_cost(watts, power_factor, price): @@ -45,4 +50,6 @@ def get_cost(watts, power_factor, price): :param: price: float - price of kWh. :return: float - cost of kWh. """ - pass + efeficiency = get_efficiency(power_factor) + kwh_amount = get_kwh_amount(watts) + return (kwh_amount * price)/efeficiency diff --git a/exercises/concept/ellens-alien-game/classes.py b/exercises/concept/ellens-alien-game/classes.py index f64d1055e3..c5443b4a20 100644 --- a/exercises/concept/ellens-alien-game/classes.py +++ b/exercises/concept/ellens-alien-game/classes.py @@ -18,8 +18,38 @@ class Alien: """ - pass + x_coordinate: int + y_coordinate: int + health: int + total_aliens_created: int = 0 + + def __init__(self, x_coordinate: int, y_coordinate: int): + """Initialize Alien object with x_coordinate and y_coordinate.""" + self.x_coordinate = x_coordinate + self.y_coordinate = y_coordinate + self.health = 3 + Alien.total_aliens_created += 1 + + def hit(self): + """Decrement Alien health by one point.""" + self.health -= 1 + def is_alive(self) -> bool: + """Return a boolean for if Alien is alive (if health is > 0).""" + return self.health > 0 + def teleport(self, new_x_coordinate: int, new_y_coordinate: int): + """Move Alien object to new coordinates.""" + self.x_coordinate = new_x_coordinate + self.y_coordinate = new_y_coordinate + def collision_detection(self, other): + """Implementation TBD.""" + pass + def alien_count(self) -> int: + """Return the total number of Alien instances created.""" + return Alien.total_aliens_created + + +def new_aliens_collection(coordinates: list) -> list: + """Create a collection of Alien objects from a list of coordinates.""" + return [Alien(x, y) for x, y in coordinates] -#TODO (Student): Create the new_aliens_collection() function below to call your Alien class with a list of coordinates - diff --git a/exercises/concept/ghost-gobble-arcade-game/arcade_game.py b/exercises/concept/ghost-gobble-arcade-game/arcade_game.py index adb546aa1c..f27df85d70 100644 --- a/exercises/concept/ghost-gobble-arcade-game/arcade_game.py +++ b/exercises/concept/ghost-gobble-arcade-game/arcade_game.py @@ -13,7 +13,7 @@ def eat_ghost(power_pellet_active, touching_ghost): """ - pass + return power_pellet_active and touching_ghost def score(touching_power_pellet, touching_dot): @@ -28,7 +28,7 @@ def score(touching_power_pellet, touching_dot): """ - pass + return touching_power_pellet or touching_dot def lose(power_pellet_active, touching_ghost): @@ -42,7 +42,7 @@ def lose(power_pellet_active, touching_ghost): bool: Has the player lost the game? """ - pass + return not power_pellet_active and touching_ghost def win(has_eaten_all_dots, power_pellet_active, touching_ghost): @@ -57,4 +57,4 @@ def win(has_eaten_all_dots, power_pellet_active, touching_ghost): bool: Has the player won the game? """ - pass + return has_eaten_all_dots and not lose(power_pellet_active, touching_ghost) diff --git a/exercises/concept/guidos-gorgeous-lasagna/lasagna.py b/exercises/concept/guidos-gorgeous-lasagna/lasagna.py index bdf8ca9b77..4c362bbc25 100644 --- a/exercises/concept/guidos-gorgeous-lasagna/lasagna.py +++ b/exercises/concept/guidos-gorgeous-lasagna/lasagna.py @@ -9,10 +9,10 @@ #TODO (student): define your EXPECTED_BAKE_TIME (required) and PREPARATION_TIME (optional) constants below. - +EXPECTED_BAKE_TIME = 40 #TODO (student): Remove 'pass' and complete the 'bake_time_remaining()' function below. -def bake_time_remaining(): +def bake_time_remaining(elapsed_bake_time): """Calculate the bake time remaining. Parameters: @@ -26,18 +26,42 @@ def bake_time_remaining(): based on the `EXPECTED_BAKE_TIME`. """ - pass + return EXPECTED_BAKE_TIME - elapsed_bake_time #TODO (student): Define the 'preparation_time_in_minutes()' function below. # To avoid the use of magic numbers (see: https://en.wikipedia.org/wiki/Magic_number_(programming)), you should define a PREPARATION_TIME constant. # You can do that on the line below the 'EXPECTED_BAKE_TIME' constant. # This will make it easier to do calculations, and make changes to your code. - +def preparation_time_in_minutes(number_of_layers): + """Calculate the preparation time based on the number of layers. + Parameters: + number_of_layers (int): The number of layers in the lasagna. + Returns: + int: The total preparation time (in minutes) based on the number of layers. + This function takes an integer representing the number of lasagna layers and calculates the total preparation time + by multiplying the number of layers by the preparation time per layer (2 minutes). + """ + return number_of_layers * 2 #TODO (student): define the 'elapsed_time_in_minutes()' function below. +def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time): + """Calculate the elapsed cooking time. + + Parameters: + number_of_layers (int): The number of layers in the lasagna. + elapsed_bake_time (int): Time the lasagna has been baking in the oven. + + Returns: + int: The total time elapsed (in minutes) preparing and baking. + This function takes two integers representing the number of lasagna + layers and the time already spent baking the lasagna. It calculates + the total elapsed minutes spent cooking (preparing + baking). + + """ + return preparation_time_in_minutes(number_of_layers) + elapsed_bake_time # TODO (student): Remember to go back and add docstrings to all your functions diff --git a/exercises/concept/inventory-management/dicts.py b/exercises/concept/inventory-management/dicts.py index ae17da80e1..ddf1088372 100644 --- a/exercises/concept/inventory-management/dicts.py +++ b/exercises/concept/inventory-management/dicts.py @@ -11,7 +11,13 @@ def create_inventory(items): dict: The inventory dictionary. """ - pass + inventory = {} + for item in items: + if item in inventory: + inventory[item] += 1 + else: + inventory[item] = 1 + return inventory def add_items(inventory, items): @@ -25,7 +31,14 @@ def add_items(inventory, items): dict: The inventory updated with the new items. """ - pass + + for item in items: + if item in inventory: + inventory[item] += 1 + else: + inventory[item] = 1 + return inventory + def decrement_items(inventory, items): @@ -39,7 +52,13 @@ def decrement_items(inventory, items): dict: Updated inventory with items decremented. """ - pass + for item in items: + if item in inventory: + if inventory[item] > 0: + inventory[item] -= 1 + + + return inventory def remove_item(inventory, item): @@ -52,8 +71,10 @@ def remove_item(inventory, item): Returns: dict: Updated inventory with item removed. Current inventory if item does not match. """ + if item in inventory: + del inventory[item] + return inventory - pass def list_inventory(inventory): @@ -65,5 +86,9 @@ def list_inventory(inventory): Returns: list[tuple]: List of key, value tuples from the inventory dictionary. """ + list_of_items = [] + for key, value in inventory.items(): + if value > 0: + list_of_items.append((key, value)) + return list_of_items - pass diff --git a/exercises/concept/little-sisters-essay/string_methods.py b/exercises/concept/little-sisters-essay/string_methods.py index 3c1797741c..d5e56c9f41 100644 --- a/exercises/concept/little-sisters-essay/string_methods.py +++ b/exercises/concept/little-sisters-essay/string_methods.py @@ -11,7 +11,10 @@ def capitalize_title(title): str: The title string in title case (first letters capitalized). """ - pass + first_letters = title.split() + for i in range(len(first_letters)): + first_letters[i] = first_letters[i].capitalize() + return " ".join(first_letters) def check_sentence_ending(sentence): @@ -24,7 +27,10 @@ def check_sentence_ending(sentence): bool: Is the sentence punctuated correctly? """ - pass + if sentence.endswith("."): + return True + else: + return False def clean_up_spacing(sentence): @@ -37,7 +43,8 @@ def clean_up_spacing(sentence): str: A sentence that has been cleaned of leading and trailing space characters. """ - pass + words = sentence.split() + return " ".join(words) def replace_word_choice(sentence, old_word, new_word): @@ -52,4 +59,11 @@ def replace_word_choice(sentence, old_word, new_word): str: Input sentence with new words in place of old words. """ - pass + words = sentence.split() + for i in range(len(words)): + if words[i] == old_word or words[i] == old_word + "." or words[i] == old_word + ",": + if words[i][-1] in [".", ","]: + words[i] = new_word + words[i][-1] + else: + words[i] = new_word + return " ".join(words) diff --git a/exercises/concept/little-sisters-vocab/strings.py b/exercises/concept/little-sisters-vocab/strings.py index de0e37edf3..0cb6b887de 100644 --- a/exercises/concept/little-sisters-vocab/strings.py +++ b/exercises/concept/little-sisters-vocab/strings.py @@ -11,7 +11,7 @@ def add_prefix_un(word): str: Root word prepended with 'un'. """ - pass + return 'un' + word def make_word_groups(vocab_words): @@ -32,7 +32,13 @@ def make_word_groups(vocab_words): """ - pass + answer = '' + for word in vocab_words: + if word == vocab_words[0]: + answer += word + else: + answer += ' :: ' + vocab_words[0] + word + return answer def remove_suffix_ness(word): @@ -53,7 +59,7 @@ def remove_suffix_ness(word): """ - pass + return word[:-5] + 'y' if word[-5] == 'i' else word[:-4] def adjective_to_verb(sentence, index): @@ -75,4 +81,5 @@ def adjective_to_verb(sentence, index): """ - pass + split_sentence = sentence.split() + return split_sentence[index].strip('.').strip(',') + 'en' diff --git a/exercises/concept/locomotive-engineer/locomotive_engineer.py b/exercises/concept/locomotive-engineer/locomotive_engineer.py index f57209b7a8..854cfa3f86 100644 --- a/exercises/concept/locomotive-engineer/locomotive_engineer.py +++ b/exercises/concept/locomotive-engineer/locomotive_engineer.py @@ -1,7 +1,7 @@ """Functions which helps the locomotive engineer to keep track of the train.""" -def get_list_of_wagons(): +def get_list_of_wagons(*wagon_ids): """Return a list of wagons, given an arbitrary amount of wagon numbers. Parameters: @@ -10,7 +10,7 @@ def get_list_of_wagons(): Returns: list: A list of wagon numbers. """ - pass + return list(wagon_ids) def fix_list_of_wagons(each_wagons_id, missing_wagons): @@ -23,10 +23,17 @@ def fix_list_of_wagons(each_wagons_id, missing_wagons): Returns: list[int]: The corrected list of wagons. """ - pass + locomotive=1 + posiio_one=each_wagons_id[0] + position_two=each_wagons_id[1] + each_wagons_id.remove(each_wagons_id[0]) + each_wagons_id.remove(each_wagons_id[0]) + each_wagons_id.remove(locomotive) + list_of_wagons = [locomotive] + missing_wagons +each_wagons_id+ [posiio_one, position_two] + return list_of_wagons -def add_missing_stops(route): +def add_missing_stops(route,**stops): """Add missing stops to route dict. Parameters: @@ -36,7 +43,11 @@ def add_missing_stops(route): Returns: dict: The updated route dictionary. """ - pass + response={} + response['from']=route['from'] + response['to']=route['to'] + response["stops"] = list(stops.values()) + return response def extend_route_information(route, more_route_information): @@ -49,7 +60,7 @@ def extend_route_information(route, more_route_information): Returns: dict: The extended route information. """ - pass + return route|more_route_information def fix_wagon_depot(wagons_rows): @@ -61,4 +72,4 @@ def fix_wagon_depot(wagons_rows): Returns: list[list[tuple]]: the list of rows of wagons. """ - pass + return [list(wagons) for wagons in zip(*wagons_rows)] diff --git a/exercises/concept/log-levels/enums.py b/exercises/concept/log-levels/enums.py index ebe4bffe5b..59d8b8eb77 100644 --- a/exercises/concept/log-levels/enums.py +++ b/exercises/concept/log-levels/enums.py @@ -4,7 +4,26 @@ class LogLevel(Enum): """Represent different log levels by their verbose codes.""" - pass + TRACE = "TRC" + DEBUG = "DBG" + INFO = "INF" + WARNING = "WRN" + WARN = "WRN" + ERROR = "ERR" + FATAL = "FTL" + UNKNOWN = "UKN" + +class LogLevelInt(Enum): + """Represent different log levels by their short codes.""" + + TRACE = 0 + DEBUG = 1 + INFO = 4 + WARNING = 5 + WARN = 5 + ERROR = 6 + FATAL = 7 + UNKNOWN = 42 def parse_log_level(message): @@ -14,7 +33,11 @@ def parse_log_level(message): :return: enum - 'LogLevel.'. Return 'LogLevel.Unknown' if an unknown severity is passed. """ - pass + str_split = message.split(':') + lvl = str_split[0][1:-1] + if lvl in [level.value for level in LogLevel]: + return LogLevel(lvl) + return LogLevel('UKN') def convert_to_short_log(log_level, message): @@ -25,7 +48,8 @@ def convert_to_short_log(log_level, message): :return: enum - 'LogLevelInt.` e.g. 'LogLevelInt.5' """ - pass + answer = f"{LogLevelInt[log_level.name].value}:{message}" + return answer def get_warn_alias(): @@ -34,7 +58,7 @@ def get_warn_alias(): :return: enum - 'LogLevel'.' """ - pass + return LogLevel.WARN def get_members(): @@ -43,4 +67,4 @@ def get_members(): :return: list of tuples - [(name1, value1), (name2, value2)] """ - pass + return [(level.name, level.value) for level in LogLevel] diff --git a/exercises/concept/making-the-grade/loops.py b/exercises/concept/making-the-grade/loops.py index 5bc0c72722..d79287bf50 100644 --- a/exercises/concept/making-the-grade/loops.py +++ b/exercises/concept/making-the-grade/loops.py @@ -11,7 +11,9 @@ def round_scores(student_scores): list[int]: Student scores *rounded* to the nearest integer value. """ - pass + for i in range(len(student_scores)): + student_scores[i] = round(student_scores[i]) + return student_scores def count_failed_students(student_scores): @@ -24,7 +26,11 @@ def count_failed_students(student_scores): int: The count of student scores at or below 40. """ - pass + count = 0 + for score in student_scores: + if score <= 40: + count += 1 + return count def above_threshold(student_scores, threshold): @@ -38,7 +44,11 @@ def above_threshold(student_scores, threshold): list[int]: Integer scores that are at or above the "best" threshold. """ - pass + list_of_best_scores = [] + for score in student_scores: + if score >= threshold: + list_of_best_scores.append(score) + return list_of_best_scores def letter_grades(highest): @@ -58,7 +68,11 @@ def letter_grades(highest): 86 <= "A" <= 100 """ - pass + step = (highest - 40) // 4 + thresholds = [] + for i in range(4): + thresholds.append(41 + i * step) + return thresholds def student_ranking(student_scores, student_names): @@ -72,7 +86,10 @@ def student_ranking(student_scores, student_names): list[str]: Strings in format [". : "]. """ - pass + final_list = [] + for i in range(len(student_scores)): + final_list.append(f"{i + 1}. {student_names[i]}: {student_scores[i]}") + return final_list def perfect_score(student_info): @@ -84,5 +101,8 @@ def perfect_score(student_info): Returns: list: First `[, 100]` found OR `[]` if no student score of 100 is found. """ - - pass + + for student in student_info: + if student[1] == 100: + return student + return [] diff --git a/exercises/concept/mecha-munch-management/dict_methods.py b/exercises/concept/mecha-munch-management/dict_methods.py index a2a535c4b7..61b19b5ca3 100644 --- a/exercises/concept/mecha-munch-management/dict_methods.py +++ b/exercises/concept/mecha-munch-management/dict_methods.py @@ -12,7 +12,13 @@ def add_item(current_cart, items_to_add): dict: The updated user cart dictionary. """ - pass + for item in items_to_add: + if item in current_cart.keys(): + current_cart[item]+=1 + else: + current_cart[item]=1 + return current_cart + def read_notes(notes): @@ -24,8 +30,10 @@ def read_notes(notes): Returns: dict: A user shopping cart dictionary. """ - - pass + new_dic={} + for item in notes: + new_dic[item]=1 + return new_dic def update_recipes(ideas, recipe_updates): @@ -38,8 +46,9 @@ def update_recipes(ideas, recipe_updates): Returns: dict: The updated "recipe ideas" dict. """ - - pass + + ideas.update(recipe_updates) + return ideas def sort_entries(cart): @@ -52,7 +61,7 @@ def sort_entries(cart): dict: A user's shopping cart sorted in alphabetical order. """ - pass + return dict(sorted(cart.items())) def send_to_store(cart, aisle_mapping): @@ -65,8 +74,12 @@ def send_to_store(cart, aisle_mapping): Returns: dict: The fulfillment dictionary ready to send to store. """ + fulfillment_cart = {} - pass + for key in cart.keys(): + fulfillment_cart[key] = [cart[key]] + aisle_mapping[key] + + return dict(sorted(fulfillment_cart.items(), reverse=True)) def update_store_inventory(fulfillment_cart, store_inventory): @@ -80,4 +93,12 @@ def update_store_inventory(fulfillment_cart, store_inventory): dict: The store_inventory updated. """ - pass + + for key in fulfillment_cart.keys(): + value=store_inventory[key][0]-fulfillment_cart[key][0] + if value<=0: + value='Out of Stock' + store_inventory[key][0]=value + return store_inventory + + diff --git a/exercises/concept/meltdown-mitigation/conditionals.py b/exercises/concept/meltdown-mitigation/conditionals.py index 01bbf5af4d..a4c02bc4d5 100644 --- a/exercises/concept/meltdown-mitigation/conditionals.py +++ b/exercises/concept/meltdown-mitigation/conditionals.py @@ -19,7 +19,11 @@ def is_criticality_balanced(temperature, neutrons_emitted): """ - pass + temp_condition = temperature < 800 + neutrons_condition = neutrons_emitted > 500 + product_condition = temperature * neutrons_emitted < 500000 + + return temp_condition and neutrons_condition and product_condition def reactor_efficiency(voltage, current, theoretical_max_power): @@ -45,7 +49,17 @@ def reactor_efficiency(voltage, current, theoretical_max_power): where generated power = voltage * current """ - pass + generated_power = voltage * current + efficiency_percentage = (generated_power / theoretical_max_power) * 100 + + if efficiency_percentage >= 80: + return 'green' + elif 60 <= efficiency_percentage < 80: + return 'orange' + elif 30 <= efficiency_percentage < 60: + return 'red' + else: + return 'black' def fail_safe(temperature, neutrons_produced_per_second, threshold): @@ -65,4 +79,13 @@ def fail_safe(temperature, neutrons_produced_per_second, threshold): 3. 'DANGER' -> `temperature * neutrons per second` is not in the above-stated ranges """ - pass + product = temperature * neutrons_produced_per_second + lower_bound = 0.9 * threshold + upper_bound = 1.1 * threshold + + if product < lower_bound: + return 'LOW' + elif lower_bound <= product <= upper_bound: + return 'NORMAL' + else: + return 'DANGER'