human
Total time required to travel a path denoted by a given string | Function to calculate time taken to travel the path.
Stores total time.
Initial position.
Stores visited segments.
Check whether segment is present in the set.
Increment the value of time by 2.
Insert segment into the set.
Print the value of time.
Driver Code"
How can the above be solved in Python?
 What is a code to total time required to travel a path denoted by a given string and the other steps required?
assistant
#Here is code to total time required to travel a path denoted by a given string and the other steps required.
 def calcTotalTime ( path ) :
	time = 0
	x = 0
	y = 0
	s = set ( [ ] )
	for i in range ( len ( path ) ) :
		p = x
		q = y
		if ( path [ i ] == ' N ' ) :
			y += 1
		elif ( path [ i ] == ' S ' ) :
			y -= 1
		elif ( path [ i ] == ' E ' ) :
			x += 1
		elif ( path [ i ] == ' W ' ) :
			x -= 1
		if ( p + x , q + y ) not in s :
			time += 2
			s . add ( ( p + x , q + y ) )
		else :
			time += 1
	print ( time )
if __name__ == " _ _ main _ _ " :
	path = " NSE "
	calcTotalTime ( path )