As part of an assignment for a calculus class, I have to write code for the prime number counting function $p(n)$, I have no problem creating the function itself, but for I want it as a function, rather than having to set a value for n each time individually, I would like to just be able to put f[(some value)] and have it return p(some value). However, when I write:
f[x_] = Total[Table[If[PrimeQ[n] == True, 1, 0], {n, 1, x, 1}]]
and subsequently follow with f[15]
(an example value), it gives me the following error:
Table: iterator {n,1,x,1} does not have appropriate bounds
Is it just not possible to have the variable be within the bounds?
f[x_] :=
instead off[x_] =
$\endgroup$ – Jason B. Sep 6 '18 at 22:23PrimePi
$\endgroup$ – roman465 Sep 7 '18 at 0:19