Created
June 8, 2021 00:15
-
-
Save jamesfe/18b8f3d20789d561a919d4723d9e62bc to your computer and use it in GitHub Desktop.
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 good_stick_three_character_strings_together(x, y): | |
| """Should return x, a space, then y; for example: | |
| x = dog | |
| y = cat | |
| returns "dog cat" | |
| """ | |
| assert type(x) == str and type(y) == str | |
| assert len(x) == 3 and len(y) == 3 | |
| return x + ' ' + y | |
| def bad_stick_three_character_strings_together(x, y): | |
| """Should return x, a space, then y; for example: | |
| x = dog | |
| y = cat | |
| returns "dog cat" | |
| """ | |
| assert len(x) == 3 and len(y) == 3 | |
| assert type(x) == str and type(y) == str | |
| return x + ' ' + y | |
| print('some cases that work') | |
| print(good_stick_three_character_strings_together('dog', 'cat')) | |
| print(bad_stick_three_character_strings_together('dog', 'cat')) | |
| print('cases that will break; we want an AssertionError, not a TypeError') | |
| # this first one gives us a nice error | |
| try: | |
| print(good_stick_three_character_strings_together(99, 'cat')) | |
| except AssertionError: | |
| print('got an assertion error') | |
| # this one gives us an ugly error | |
| try: | |
| print(bad_stick_three_character_strings_together(99, 'cat')) | |
| except AssertionError: | |
| print('got an assertion error') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment