Created
March 26, 2018 13:06
-
-
Save pavdmyt/5c7b382b5c76928cc41e71305819d2b0 to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
Some func problems | |
~~~~~~~~~~~~~~~~~~ | |
Provide your solutions and run this module. | |
""" | |
def add(a, b): | |
"""Returns sum of two numbers.""" | |
def cube(n): | |
"""Returns cube (n^3) of the given number.""" | |
def is_odd(n): | |
"""Return True if given number is odd, False otherwise.""" | |
def print_nums(num): | |
"""Prints all natural numbers less than given `num`.""" | |
def print_even(num): | |
"""Prints all even nums less than a given `num`.""" | |
def cube_lst(lst): | |
"""Returns a list of cubes based on input list.""" | |
# === Don't modify below === | |
def test(): | |
assert add(3, 2) == 5 | |
assert add(8, -1) == 7 | |
assert cube(3) == 27 | |
assert cube(-1) == -1 | |
assert is_odd(3) | |
assert is_odd(5) | |
assert is_odd(11) | |
assert not is_odd(2) | |
assert cube_lst([1, 2, 5]) == [1, 8, 125] | |
def main(): | |
try: | |
test() | |
except AssertionError: | |
print("=== Tests FAILED ===") | |
else: | |
print("=== Success! ===") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment