human
Can you provide a code to count numbers up to N having digit D in its octal representation and the other steps required given the following:
Count numbers up to N having digit D in its octal representation | Function to count the numbers in given range whose octal representation contains atleast digit , d.
Store count of numbers up to n whose octal representation contains digit d.
Iterate over the range [ 1 , n ].
Calculate digit of i in octal representation.
Check if octal representation of x contains digit d.
Update total.
Update x.
Prthe answer.
Driver Code.
Given N and D.
Counts and prints numbers up to N having D as a digit in its octal representation"
How can the above be solved in Python?
assistant
#Here is code to count numbers up to N having digit D in its octal representation and the other steps required.
 def countNumbers ( n , d ) :
	total = 0
	for i in range ( 1 , n + 1 ) :
		x = i
		while ( x > 0 ) :
			if ( x % 8 == d ) :
				total += 1
				break
			x = x // 8
	print ( total )
if __name__ == ' _ _ main _ _ ' :
	n , d = 20 , 7
	countNumbers ( n , d )