human
Check if a number is in given base or not | Python3 program to check if given number is in given base or not ..
Allowed bases are till 16 ( Hexadecimal ).
If base is below or equal to 10 , then all digits should be from 0 to 9..
If base is below or equal to 16 , then all digits should be from 0 to 9 or from 'A.
Driver code"
How can the above be solved in Python?
 Give me a code to check if a number is in given base or not and the other steps required?
assistant
#Here is code to check if a number is in given base or not and the other steps required.
 def isInGivenBase ( Str , base ) :
	if ( base > 16 ) :
		return False
	elif ( base <= 10 ) :
		for i in range ( len ( Str ) ) :
			if ( Str [ i ] . isnumeric ( ) and ( ord ( Str [ i ] ) >= ord ( '0' ) and ord ( Str [ i ] ) < ( ord ( '0' ) + base ) ) == False ) :
				return False
'
	else :
		for i in range ( len ( Str ) ) :
			if ( Str [ i ] . isnumeric ( ) and ( ( ord ( Str [ i ] ) >= ord ( '0' ) and ord ( Str [ i ] ) < ( ord ( '0' ) + base ) ) or ( ord ( Str [ i ] ) >= ord ( ' A ' ) and ord ( Str [ i ] ) < ( ord ( ' A ' ) + base - 10 ) ) ) == False ) :
				return False
	return True
Str = " AF87"
if ( isInGivenBase ( Str , 16 ) ) :
	print ( " Yes " )
else :
	print ( " No " )