From 067a9b513628c8aa91fb1c74f44dfa5ee3ef6c1d Mon Sep 17 00:00:00 2001 From: mvhb Date: Sun, 6 Oct 2019 15:55:55 -0300 Subject: [PATCH] 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 --- sorts/stooge_sort.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sorts/stooge_sort.py b/sorts/stooge_sort.py index 8cccd1e8c..089b01a4d 100644 --- a/sorts/stooge_sort.py +++ b/sorts/stooge_sort.py @@ -1,11 +1,14 @@ def stooge_sort(arr): """ - >>> arr = [2, 4, 5, 3, 1] - >>> stooge_sort(arr) - >>> print(arr) - [1, 2, 3, 4, 5] + Examples: + >>> stooge_sort([18.1, 0, -7.1, -1, 2, 2]) + [-7.1, -1, 0, 2, 2, 18.1] + + >>> stooge_sort([]) + [] """ stooge(arr, 0, len(arr) - 1) + return arr def stooge(arr, i, h): @@ -29,3 +32,8 @@ def stooge(arr, i, h): # Recursively sort first 2/3 elements 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))