human
Give me a code to the Stock Span Problem and the other steps required given the following:
The Stock Span Problem | Fills list S [ ] with span values.
Span value of first day is always 1.
Calculate span value of remaining days by linearly checking previous days.
Initialize span value.
Traverse left while the next element on left is smaller than price [ i ].
A utility function to print elements of array.
Driver program to test above function.
Fill the span values in list S [ ].
print the calculated span values"
How can the above be solved in Python?
assistant
#Here is code to the Stock Span Problem and the other steps required.
 def calculateSpan ( price , n , S ) :
	S [ 0 ] = 1
	for i in range ( 1 , n , 1 ) :
		S [ i ] = 1
		j = i - 1
		while ( j >= 0 ) and ( price [ i ] >= price [ j ] ) :
			S [ i ] += 1
			j -= 1
def printArray ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
price = [ 10 , 4 , 5 , 90 , 120 , 80 ]
n = len ( price )
S = [ None ] * n
calculateSpan ( price , n , S )
printArray ( S , n )