adding input option and increasing the number of doctest (#1281)

* adding input option and incresing the number of doctest

* mixing positive and negative numbers in the same test case
This commit is contained in:
mvhb 2019-10-06 15:55:55 -03:00 committed by Christian Clauss
parent 9cc9f67d64
commit 067a9b5136

View File

@ -1,11 +1,14 @@
def stooge_sort(arr): def stooge_sort(arr):
""" """
>>> arr = [2, 4, 5, 3, 1] Examples:
>>> stooge_sort(arr) >>> stooge_sort([18.1, 0, -7.1, -1, 2, 2])
>>> print(arr) [-7.1, -1, 0, 2, 2, 18.1]
[1, 2, 3, 4, 5]
>>> stooge_sort([])
[]
""" """
stooge(arr, 0, len(arr) - 1) stooge(arr, 0, len(arr) - 1)
return arr
def stooge(arr, i, h): def stooge(arr, i, h):
@ -29,3 +32,8 @@ def stooge(arr, i, h):
# Recursively sort first 2/3 elements # Recursively sort first 2/3 elements
stooge(arr, i, (h - t)) stooge(arr, i, (h - t))
if __name__ == "__main__":
user_input = input("Enter numbers separated by a comma:\n").strip()
unsorted = [int(item) for item in user_input.split(",")]
print(stooge_sort(unsorted))