Created
November 19, 2019 19:08
-
-
Save erdavids/3084a43d7c397d8e00b0de2ad20f6168 to your computer and use it in GitHub Desktop.
Cassidoo Interview - Nov 18
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 substring(*arg): | |
# Unknown number of arguments | |
arg_length = len(arg) | |
# Input string and output | |
orig = '' | |
out = '' | |
# Return original string if no other parameters are given | |
if (arg_length > 1): | |
orig = arg[0] | |
else: | |
return arg[0] | |
# Iterate through the original input | |
for c in range(len(orig)): | |
# Build the output string | |
if (c >= arg[1]): | |
out += orig[c] | |
# End output string at third parameter if it exists | |
if (arg_length == 3 and c >= arg[2]): | |
return out | |
# Return substring from second parameter to the end of the string | |
return out | |
def main(): | |
print(substring("hello world!", 1, 5)) | |
print(substring("hello world!", 6)) | |
print(substring("hello world!")) | |
print(substring("hello world!", 0)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment