Ask coding questions

← Back to all posts
How to select natural numbers in Python
Nxt27755

I want to make something that knows if something is a prime number, and I want it to recognize a natural number. How to make something that recognizes if your input is a natural number (A number without numbers behind the ,)

Voters
Nxt27755
Comments
hotnewtop
RYANTADIPARTHI

try this:

SixBeeps

@RYANTADIPARTHI 5.2 passes this check, but is not a natural number.

RYANTADIPARTHI

@SixBeeps edited.

SixBeeps

I believe since you're using Python you could just do this:

RYANTADIPARTHI

could you explain more what you mean by a natural number?

SixBeeps

@RYANTADIPARTHI In mathematics, the set of natural numbers is the set of all positive integers greater than 0 (ℕ ⊆ ℤ s.t. x ∈ ℕ, x > 0)

RYANTADIPARTHI

@SixBeeps ok thanks!