human
Painting Fence Algorithm | Returns count of ways to color k posts using k colors.
There are k ways to color first post.
There are 0 ways for single post to violate ( same color_ and k ways to not violate ( different color ).
Fill for 2 posts onwards.
Current same is same as previous diff.
We always have k - 1 choices for next post.
Total choices till i ..
Driver code"
How can the above be solved in Python?

What is a code to painting Fence Algorithm and the other steps required?
assistant
#Here is code to painting Fence Algorithm and the other steps required.
 def countWays ( n , k ) :
	total = k
	mod = 1000000007
	same , diff = 0 , k
	for i in range ( 2 , n + 1 ) :
		same = diff
		diff = total * ( k - 1 )
		diff = diff % mod
		total = ( same + diff ) % mod
	return total
if __name__ == " _ _ main _ _ " :
	n , k = 3 , 2
	print ( countWays ( n , k ) )