If I am interpreting your question correctly, you simply need to devise a very simple list comprehension program.
Getting the square root of everything between zero and n is not necessary. Did you mean square?
Here’s my solution:
def nbDig(n,d):
int_list = str([str(x*x) for x in range(0,n+1)]).count(str(d))
return int_list
I can test it like so:
nbDig(12,1)
This returns 7.
EDIT: I didn’t realize calling .replace was totally unnecessary. Thanks for the feedback!
3
solved how can I square the numbers between 0 and any input with extremely large numbers in python [closed]