human
Can you provide a code to difference between two given times and the other steps required given the following:
Difference between two given times | Remove ' : ' and convert it into an integer.
Main function which finds difference.
Change string ( eg . 2 : 21 -- > 221 , 00 : 23 -- > 23 ).
Difference between hours.
Difference between minutes.
Convert answer again in string with ' : '.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to difference between two given times and the other steps required.
 def removeColon ( s ) :
	if ( len ( s ) == 4 ) :
		s = s [ : 1 ] + s [ 2 : ]
	if ( len ( s ) == 5 ) :
		s = s [ : 2 ] + s [ 3 : ]
	return int ( s )
def diff ( s1 , s2 ) :
	time1 = removeColon ( s1 )
	time2 = removeColon ( s2 )
	hourDiff = time2 // 100 - time1 // 100 - 1 ;
	minDiff = time2 % 100 + ( 60 - time1 % 100 )
	if ( minDiff >= 60 ) :
		hourDiff += 1
		minDiff = minDiff - 60
	res = str ( hourDiff ) + ' : ' + str ( minDiff )
	return res
s1 = "14:00"
s2 = "16:45"
print ( diff ( s1 , s2 ) )