From dc584f16585b00df02301de122e4b4970ce9f505 Mon Sep 17 00:00:00 2001 From: S-Sanyal Date: Wed, 3 Oct 2018 20:13:34 +0530 Subject: [PATCH 1/4] Made the code Python 3 compatible --- data_structures/Stacks/Stock-Span-Problem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/Stacks/Stock-Span-Problem.py b/data_structures/Stacks/Stock-Span-Problem.py index 658ac3cbf..ecef7ecc6 100644 --- a/data_structures/Stacks/Stock-Span-Problem.py +++ b/data_structures/Stacks/Stock-Span-Problem.py @@ -37,7 +37,7 @@ def calculateSpan(price, S): # A utility function to print elements of array def printArray(arr, n): for i in range(0,n): - print arr[i], + print (arr[i]), # Driver program to test above function From c74b2732d9282fa68c0de666d39635e6ec018f03 Mon Sep 17 00:00:00 2001 From: S-Sanyal Date: Wed, 3 Oct 2018 21:37:46 +0530 Subject: [PATCH 2/4] Updated --- data_structures/Stacks/Stock-Span-Problem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/Stacks/Stock-Span-Problem.py b/data_structures/Stacks/Stock-Span-Problem.py index ecef7ecc6..2081166bb 100644 --- a/data_structures/Stacks/Stock-Span-Problem.py +++ b/data_structures/Stacks/Stock-Span-Problem.py @@ -37,7 +37,7 @@ def calculateSpan(price, S): # A utility function to print elements of array def printArray(arr, n): for i in range(0,n): - print (arr[i]), + print (arr[i],end =" ") # Driver program to test above function From 054b4b31f42a2bfe5dafed66fa88cb477aa63098 Mon Sep 17 00:00:00 2001 From: S-Sanyal Date: Wed, 3 Oct 2018 21:52:30 +0530 Subject: [PATCH 3/4] Made compatible for all versions of python --- .vscode/settings.json | 3 +++ data_structures/Stacks/Stock-Span-Problem.py | 1 + 2 files changed, 4 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..615aafb03 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/usr/bin/python3" +} \ No newline at end of file diff --git a/data_structures/Stacks/Stock-Span-Problem.py b/data_structures/Stacks/Stock-Span-Problem.py index 2081166bb..f64c712bb 100644 --- a/data_structures/Stacks/Stock-Span-Problem.py +++ b/data_structures/Stacks/Stock-Span-Problem.py @@ -6,6 +6,7 @@ The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day. ''' +from __future__ import print_function def calculateSpan(price, S): n = len(price) From 63c7e8ede14ae7200043c59bf4faaf6104c1b13e Mon Sep 17 00:00:00 2001 From: Harshil Date: Thu, 4 Oct 2018 11:34:50 +0200 Subject: [PATCH 4/4] Minor update Changed two characters which were the root cause of 'SyntaxError: Non-ASCII character '\xe2' in file main.py, but no encoding declared' --- data_structures/Stacks/Stock-Span-Problem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/Stacks/Stock-Span-Problem.py b/data_structures/Stacks/Stock-Span-Problem.py index f64c712bb..9628864ed 100644 --- a/data_structures/Stacks/Stock-Span-Problem.py +++ b/data_structures/Stacks/Stock-Span-Problem.py @@ -1,8 +1,8 @@ ''' The stock span problem is a financial problem where we have a series of n daily -price quotes for a stock and we need to calculate span of stock’s price for all n days. +price quotes for a stock and we need to calculate span of stock's price for all n days. -The span Si of the stock’s price on a given day i is defined as the maximum +The span Si of the stock's price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day. ''' @@ -49,4 +49,4 @@ S = [0 for i in range(len(price)+1)] calculateSpan(price, S) # Print the calculated span values -printArray(S, len(price)) \ No newline at end of file +printArray(S, len(price))