This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def equilateral(sides): | |
return len(set(sides)) == 1 and (sides[0] + sides[1] >= sides[2] and sides[0] + sides[2] >= sides[1] and sides[1] + sides[2] >= sides[0]) and 0 not in sides | |
def isosceles(sides): | |
return len(set(sides)) <= 2 and (sides[0] + sides[1] >= sides[2] and sides[0] + sides[2] >= sides[1] and sides[1] + sides[2] >= sides[0]) | |
def scalene(sides): | |
return len(set(sides)) == 3 and (sides[0] + sides[1] >= sides[2] and sides[0] + sides[2] >= sides[1] and sides[1] + sides[2] >= sides[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def leap_year(year): | |
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eat_ghost(power_pellet_active, touching_ghost): | |
return power_pellet_active and touching_ghost | |
def score(touching_power_pellet, touching_dot): | |
return touching_power_pellet or touching_dot | |
def lose(power_pellet_active, touching_ghost): | |
return not power_pellet_active and touching_ghost | |
def win(has_eaten_all_dots, power_pellet_active, touching_ghost): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square_root(number): | |
return number ** 0.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_armstrong_number(number): | |
return number == sum(int(digit)**len(str(number)) for digit in str(number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square(number): | |
if number not in range(1, 65): | |
raise ValueError("square must be between 1 and 64") | |
else: | |
return pow(2, number-1) | |
def total(): | |
return pow(2, 64) - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def steps(number): | |
if number < 1 or type(number) != int: | |
raise ValueError("Only positive integers are allowed") | |
step_count = 0 | |
while number != 1: | |
number = number // 2 if number % 2 == 0 else 3 * number + 1 | |
step_count += 1 | |
return step_count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bake_time_remaining(elapsed_bake_time): | |
return EXPECTED_BAKE_TIME - elapsed_bake_time | |
def preparation_time_in_minutes(number_of_layers): | |
return number_of_layers * PREPARATION_TIME | |
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time): | |
return preparation_time_in_minutes(number_of_layers) + int(elapsed_bake_time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def exchange_money(budget, exchange_rate): | |
return budget / exchange_rate | |
def get_change(budget, exchanging_value): | |
return budget - exchanging_value | |
def get_value_of_bills(denomination, number_of_bills): | |
return int(denomination * number_of_bills) | |
def get_number_of_bills(amount, denomination): | |
return amount // denomination | |
def get_leftover_of_bills(amount, denomination): | |
return amount % denomination |