Created
May 11, 2021 17:16
-
-
Save t-eckert/618032ac8dd681db1acf481e525c425d to your computer and use it in GitHub Desktop.
Solution to Rounder problem
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
""" | |
Given a positive or negative real number, round it to the next whole integer | |
closer to zero. This means if it’s positive, round down, and if it’s negative, | |
round up. Try to do this in as few characters possible! | |
""" | |
def round(number: float) -> int: | |
return int(str(number).split(".")[0]) | |
def print_and_assert(expected, actual): | |
print("expected = " + str(expected)) | |
print("actual = " + str(actual) + "\n") | |
assert expected == actual | |
if __name__ == "__main__": | |
print_and_assert(1, round(1.7)) | |
print_and_assert(-2, round(-2.1)) | |
print_and_assert(500, round(500.4)) | |
print_and_assert(-369, round(-369.5)) | |
print_and_assert(150, round(150)) | |
print_and_assert(-350, round(-350)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment