Skip to content

Instantly share code, notes, and snippets.

@pavdmyt
Created March 26, 2018 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavdmyt/5c7b382b5c76928cc41e71305819d2b0 to your computer and use it in GitHub Desktop.
Save pavdmyt/5c7b382b5c76928cc41e71305819d2b0 to your computer and use it in GitHub Desktop.
"""
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