Last active
April 4, 2021 10:39
-
-
Save CharudattaManwatkar/384eb062ed43a573b88c24720baa4432 to your computer and use it in GitHub Desktop.
Ellipsis as an alternative to None
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
# calculate nth odd number | |
def nth_odd(n): | |
if isinstance(n, int): | |
return 2 * n - 1 | |
else: | |
return None | |
# calculate the original n of nth odd number | |
def original_num(m=...): | |
if m is ...: | |
print('This function needs some input') | |
elif m is None: | |
print('Non integer input provided to nth_odd() function') | |
elif isinstance(m, int): | |
if m % 2: | |
print(f'{m} is {int((m + 1)/2)}th odd number') | |
else: | |
print(f'{m} is not an odd number') | |
original_num() | |
a = nth_odd(n='some string') | |
original_num(a) | |
b = nth_odd(5) | |
original_num(b) | |
original_num(16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment