human
Give me a code to replace all occurrences of pi with 3 given the following:
Replace all occurrences of pi with 3.14 in a given string | Function to replace all occurrences of pi in a given with 3.14.
Iterate through second last element of the string.
If current and current + 1 alphabets form the word ' pi ' append 3.14 to output.
Append the current letter.
Return the output string.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to replace all occurrences of pi with 3.
 def replacePi ( input ) :
	output = " " ;
	size = len ( input ) ;
	for i in range ( size ) :
		if ( i + 1 < size and input [ i ] == ' p ' and input [ i + 1 ] == ' i ' ) :
			output += "3.14" ;
			i += 1 ;
		else :
			output += input [ i ] ;
	return output ;
input = "2 ▁ * ▁ pi ▁ + ▁ 3 ▁ * ▁ pi ▁ = ▁ 5 ▁ * ▁ pi " ;
print ( replacePi ( input ) ) ;