human
Write me a code to modulus of two Hexadecimal Numbers and the other steps required given the following:
Modulus of two Hexadecimal Numbers | Function to calculate modulus of two Hexadecimal numbers.
Store all possible hexadecimal digits.
Iterate over the range [ '0' , '9' ].
Convert given string to long.
Base to get 16 power.
Store N % K.
Iterate over the digits of N.
Stores i - th digit of N.
Update ans.
Update base.
Print the answer converting into hexadecimal.
Driver Code.
Given string N and K.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to modulus of two Hexadecimal Numbers and the other steps required.
 def hexaModK ( s , k ) :
	mp = { } ;
	for i in range ( 1 , 10 ) :
		mp [ chr ( i + ord ( '0' ) ) ] = i ;
	mp [ ' A ' ] = 10 ;
	mp [ ' B ' ] = 11 ;
	mp [ ' C ' ] = 12 ;
	mp [ ' D ' ] = 13 ;
	mp [ ' E ' ] = 14 ;
	mp [ ' F ' ] = 15 ;
	m = int ( k ) ;
	base = 1 ;
	ans = 0 ;
	for i in range ( len ( s ) - 1 , - 1 , - 1 ) :
		n = mp [ s [ i ] ] % m ;
		ans = ( ans + ( base % m * n % m ) % m ) % m ;
		base = ( base % m * 16 % m ) % m ;
	ans = hex ( int ( ans ) ) [ - 1 ] . upper ( )
	print ( ans )
if __name__ == " _ _ main _ _ " :
	n = "3E8" ;
	k = "13" ;
	hexaModK ( n , k ) ;